Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, let's review first, how arrays decay and second, how declarations work.</p> <p><code>A</code> is declared as a 2D array. When <code>A</code> is used in any expression, it will "decay" to a pointer to its first element. In C, a 2D array is made up of two 1D arrays. So an element of a 2D array is a 1D array. So when <code>A</code> is used in any expression, it will decay to a pointer to the first row of <code>A</code>, which is an array of 10 ints. </p> <p><code>int (*v) [10]</code> means that <code>v</code> is a pointer to an array of 10 ints. The assignment</p> <pre><code>int (*v)[10] = A; </code></pre> <p>is an expression, so <code>A</code> there has decayed to a pointer to 10 ints as well, so the assignment is valid. </p> <p>So now when you look at <code>**v</code>, you are dereferencing first, <code>v</code>, which means you are getting what <code>v</code> points at, which is the first row of your 2D array. Then you are dereferencing <code>*v</code>, which means you are getting the first element of that first row. That is 1, so your output is 1.</p> <p>When you look at <code>**(v + 1)</code>, you are first adding 1 to the pointer <code>v</code>. Since <code>v</code> points to a row, adding 1 gets you a pointer to the next row. Then you do the double dereferencing as above and you get the first element of the next row, which is 11.</p> <p>When you look at <code>*(*v + 1)</code>, you are first dereferencing <code>v</code>, which means you get the first row. Then you add 1 to that, which gets you a pointer to the next element of the row. Then you dereference that, which gets you the 2, the second element. </p> <p>To summarize: <code>v</code> points to the whole first row. <code>*v</code> points to the first element of the first row. <code>(v + 1)</code> points to the whole second row. <code>(*v + 1)</code> points to the second element of the first row. </p> <p>After this, figuring out the rest is probably quite easy. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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