title: Arrays decaying into pointers
body: <p>Please help me understand the programs below.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
      int a[7];
      a[0] = 1976;
      a[1] = 1984;
      printf("memory location of a: %p", a); 
      printf("value at memory location %p is %d", a, *a); 
      printf("value at memory location %p is %d", &amp;a[1], a[1]);
      return 0;
  }
  </code></pre>
  
  <p><code>&amp;a[1]</code> and <code>&amp;a+1</code>. Are they same or different?</p>
  
  <pre><code>#include &lt;stdio.h&gt; 
  int main() 
  {
      int v[10];
      int **p; 
      int *a[5];
      v[0] = 1234;
      v[1] = 5678;
      a[0] = v; 
      a[1] = v+1;
      printf("%d\t%d\t%d\t%d\n", *a[0],*a[1],a[0][0],**a);
      printf("%d\n", sizeof(v));
      return 0;
  } 
  </code></pre>
  
  <p>I wanted to know how <code>*a[5]</code> is represented in memory. Is <code>*a</code> a base pointer that points to <code>a[0],a[1],a[2],a[3],a[4]</code>?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int v[10];
      int **p;
      int (*a)[10];
      a=&amp;v;
      printf("%d\n",*a);
          return 0;
  }
  </code></pre>
  
  <p><code>a=v; // gives error why?</code> does <code>v</code> here decay into <code>*v</code>. Then does <code>&amp;v</code> get decayed into <code>(*)[]v</code>? &amp; means const pointer. Here, how is it possible to set a const pointer to a non-const pointer without a typecast?</p>
  
  <p>Where does the array get stored in the memory. Does it get stored onto the data segment of the memory.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main()
  {
      int carray[5]={1,2,3,4,5};
      printf("%d\n",carray[0]);
      printf("%d\t%d\t%d\n",sizeof(carray),sizeof(&amp;carray),sizeof(&amp;carray[0]));
      return 0;
  }
  </code></pre>
  
  <p><strong>EDITED:</strong></p>
  
  <p>I have gone through some of the articles which stated that the only two possible situations where an array name cannot be decyed into pointer is the <code>sizeof</code> and <code>&amp;</code>. But in the above program <code>sizeof(&amp;carray)</code> gives the size as 4. and <code>&amp;carray</code> decays into <code>(*)[]carray</code> as its an rvalue.</p>
  
  <p>Then the statement that array name cannot get decayed into pointers on two conditions <code>sizeof</code> and <code>&amp;</code> becomes false here.</p>