title: Stack vs. heap pointers in C
body: <p>I'm currently learning C and I'm confused about memory layout and pointers.</p>
  
  <p>In the following code, it is my understanding that the array is allocated on the stack.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main () {
     int x[4];
     x[0] = 3; x[1] = 2; x[2] = 1;
     printf("%p\n",x);
     printf("%p\n", &amp;x);
  }
  </code></pre>
  
  <p>My question is, why do the two print calls output the same value?</p>
  
  <p>I tried a similar snippet using malloc (allocate on the heap), and the values differ.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main () {
     int *x = malloc(sizeof(int) * 4);
     x[0] = 3; x[1] = 2; x[2] = 1;
     printf("%p\n",x);
     printf("%p\n", &amp;x);
  }
  </code></pre>