I teach a course where students get to ask questions about programming (!): I got this question:
Why does the machine choose were variables go in memo
I would like to add few. For firmware where you know the memory map and run address, and where you compile source using your own linker script-
You can assign a custom section to a variable using section attribute and then assign a particular address to custom section through linker script. Then variable would get a fixed/assigned address.