title: How does sizeof know the size of array?
body: <p>I have codes as following:</p>
  
  <pre><code>main() {
      int array[5] = {3,6,9,-8,1};
      printf("the size of the array is %d\n", sizeof(array));
      printf("the address of array is %p\n", array);
      printf("the address of array is %p\n", &amp;array);
      int * x = array;
      printf("the address of x is %p\n", x);
      printf("the size of x is %d\n", sizeof(x));
  }
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>the size of the array is 20
  the address of array is 0x7fff02309560
  the address of array is 0x7fff02309560
  the address of x is 0x7fff02309560
  the size of x is 8
  </code></pre>
  
  <p>I know the variable <code>array</code> will be seen as a pointer to the first element of the array, so I understand the the size of x is 8. But I don't know why the size of the array is 20. Isn't it should be 8 (in a 64-bits machine)? </p>
  
  <p>Besides how does the program know that it is 20? As far as I know in C it doesn't store the number of elements. How come the <code>sizeof(array)</code> and <code>sizeof(x)</code> is different? I tracked several posts pertaining to array decaying but no idea on this problem.</p>