title: Pointer arithmetic on "neighbour" declared variables
body: <p>Could someone explain why the following code behaves differently if the 3 first printf calls are there or not ?</p>
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  int main(){
      int a = 1;
      int b = 2;
      int c = 3;
      
      int* a_ptr = &amp;a;
      
      // comment out the following 3 lines
      printf(&quot; &amp;a : %p\n&quot;, &amp;a);
      printf(&quot; &amp;b : %p\n&quot;, &amp;b);
      printf(&quot; &amp;c : %p\n&quot;, &amp;c);
  
  
      printf(&quot;*(a_ptr)   : %d\n&quot;, *(a_ptr));
      printf(&quot;*(a_ptr-1) : %d\n&quot;, *(a_ptr-1));
      printf(&quot;*(a_ptr-2) : %d\n&quot;, *(a_ptr-2));
  </code></pre>
  <p>I was playing around to learn how variables are being stacked in memory depending on the order of declaration. By printing the addresses, I see they are 1 int size apart if they are declared after each other. After printing the addreses, I just subtract 1 and 2 from the address of a and dereference it. When I print it, it shows what i'd expect, the values of a, b and c. BUT, if i do not print the addresses before, I just get a=1, while b and c seem random to me. What is going on here ? Do you get the same behaviour on your machine ?</p>
  <pre><code>// without printing the addresses
  *(a_ptr)   : 1
  *(a_ptr-1) : 4200880
  *(a_ptr-2) : 6422400
   
  // with printing 
   &amp;a : 0061FF18
   &amp;b : 0061FF14
   &amp;c : 0061FF10
  *(a_ptr)   : 1
  *(a_ptr-1) : 2
  *(a_ptr-2) : 3
  </code></pre>