Question: When I was trying to print the address of the first variable in main function, I found that the result is always same after running few times. Why? Is it in the virtual memory or physical memory?

```c
#include <stdio.h>

int main()
{
    int a;

    printf("a's address is %p\n", &a);

    return 0;
}

```

I expect the output will be different every time, but the actual output is always 0028FF3C

Answer: 
On some systems, [ASLR](https://en.wikipedia.org/wiki/Address_space_layout_randomization) is enabled, and for good reasons.

For example, on my Linux/Debian/Sid x86-64 your program gives each time different addresses:

```
repeat 10 tmp/sange
a's address is 0x7fff2768303c
a's address is 0x7ffc5d26a57c
a's address is 0x7ffcc0a4b2ac
a's address is 0x7ffeec95fd7c
a's address is 0x7ffefd5318dc
a's address is 0x7ffc544497bc
a's address is 0x7fff232f7dac
a's address is 0x7fff9dd3b65c
a's address is 0x7fff9e6858dc
a's address is 0x7ffc2876d4bc

```

To learn more, read about [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior) (e.g. [Lattner's blog](http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html)), [unspecified behavior](https://en.wikipedia.org/wiki/Unspecified_behavior), and read a good textbook about operating systems, e.g. [*Operating Systems: Three Easy Pieces*](http://pages.cs.wisc.edu/~remzi/OSTEP/) (freely downloadable)

Read also about [virtual address space](https://en.wikipedia.org/wiki/Virtual_address_space).
In any normal multi-user operating system, the addresses in your process will be virtual addresses. This is because, in normal multi-user operating systems, the operating system uses virtual address spaces to keep programs independent of each other.

The address space of your program is set up in part by a process called the loader, which loads the initial data and code of your program into memory. A simple loader will start the stack of a new program at a fixed location—it will use the same starting location every time it loads a program. Then, when your program runs, `a` will always be at the same address. Loaders operated this way for many years.

Because malicious people can sometimes take advantage of known stack addresses to attack and subvert software, some loaders now use random addresses when loading programs. This is called address space layout randomization (ASLR). When your program is loaded with a loader using ASLR, the address of `a` will vary from run to run.