Does Windows store the the address of a variable even when the program terminates?

Solution 1:

First thing, windows is not storing the address of the local variable. It is using the same memory address for running the program.

If you read this article: https://www.mandiant.com/resources/six-facts-about-address-space-layout-randomization-on-windows

"ELF images, as used in the Linux implementation of ASLR, can use position-independent executables and position-independent code in shared libraries to supply a freshly randomized address space for the main program and all its libraries on each launch—sharing the same machine code between multiple processes even where it is loaded at different addresses. Windows ASLR does not work this way. Instead, each DLL or EXE image gets assigned a random load address by the kernel the first time it is used, and as additional instances of the DLL or EXE are loaded, they receive the same load address. If all instances of an image are unloaded and that image is subsequently loaded again, the image may or may not receive the same base address; see Fact 4. Only rebooting can guarantee fresh base addresses for all images systemwide."

So this is how windows manage ASLR. Now when you re-run the program it will show same memory address. Since it is using the same address. Now if you restart your PC and re-run the program this time ASLR will change the address. So you would see different address.

This is related to security of windows. Linux implements ASLR differently so it shows different address.