Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<ol> <li><p><code>&amp;a</code> gives you the address of the array. It's of type <code>int (*)[3][3]</code>. Easy.</p></li> <li><p><code>a</code> denotes the array itself and will undergo array-to-pointer conversion to become a pointer to the array's first element. The array's first element is a subarray of type <code>int[3]</code>, so we get a pointer to that subarray. This pointer is of type <code>int (*)[3]</code>. This has the same address as before because the first subarray is at the start of the array.</p></li> <li><p>With <code>*a</code>, the array undergoes array-to-pointer conversion again to get the same pointer to the subarray as before. This is then dereference to get the subarray itself. Then this expression which denotes the subarray also undergoes array-to-pointer conversion, giving you a pointer to <em>its</em> first element. The first element is of type <code>int</code>, so the pointer is of type <code>int*</code>. The address of the first element is the same as the address of the subarray it is part of, which, as we've seen, is the same address as the entire array.</p></li> <li><p><code>&amp;a[0][0]</code> first gets you the first element of the first subarray, then takes the address of it. This gives you exactly the same pointer as in the previous point.</p></li> </ol> <p>Therefore, all of these pointers have the same value.</p> <p>Diagrammatically:</p> <pre><code> 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐ │ int │ int │ int │ int │ int │ int │ int │ int │ int │ └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘ └─────────────────────────────────────────────────────┘ &amp;a points at the entire array └─────────────────┘ a gives you a pointer to the first subarray └─────┘ *a gives you a pointer to the element 0,0 and so does &amp;a[0][0] </code></pre> <p>These regions all begin at the same address, so the pointers have the same value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload