title: The function of "main" address remains unchanged. Why does local variable address change every run?
body: <p>Please refer to the below program:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
          int a, b;
          printf("address of main =%p\n", main);
          a=3;
          printf("Address of 'a' =%p\n", &amp;a);
          return 0;
  }
  </code></pre>
  
  <p>I compiled the above program using <code>gcc</code> and then ran the binary. I am getting the below output:</p>
  
  <pre><code>[root@localhost gdb]# ./a.out
  address of main =0x400536
  Address of 'a' =0x7ffc4802cbdc
  [root@localhost gdb]# ./a.out
  address of main =0x400536
  Address of 'a' =0x7ffe2bdcd66c
  [root@localhost gdb]#
  </code></pre>
  
  <p>Same source code compiled with <code>–m32</code>, now I'm getting the output:</p>
  
  <pre><code>[root@localhost gdb]# ./a.out
  address of main =0x804841b
  Address of 'a' =0xffa6b29c
  [root@localhost gdb]# ./a.out
  address of main =0x804841b
  Address of 'a' =0xff9b808c
  </code></pre>
  
  <p>Here is my question: why the address of <code>a</code> variable range has changed while running 64 and 32 bits application in 64 bit kernel?. The <code>main</code> function address remains unchanged, Why does <code>a</code> variable addresses change every run? And where is the address of <code>a</code> variable stored? </p>