Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>A[0]</code>, <code>&amp;A</code>, <code>*A</code> all are pointers of distinct types that all point to the same memory location. Same value (sort of), different types. </p> <pre><code>Expression Symmetric Type ---------------------------------------------------------------------------- A address of first row. int[5][5] &amp;A[0][0] address of first element int* &amp;A address of 2d array int(*)[5][5] *A = *( A + 0) = A[0] = address of first element int[5] = decays to int* in a expression </code></pre> <p>My example of 5*4 dimension char arrays: </p> <pre><code> A +---201---202---203---204---206--+ 201 | +-----+-----+-----+-----+-----+| A[0] = *(A + 0)--►| 'f' | 'o' | 'r' | 'g' | 's' || 207 | +-----+-----+-----+-----+-----+| A[1] = *(A + 1)--►| 'd' | 'o' | '\0'| '\0'| '\0'|| 213 | +-----+-----+-----+-----+-----+| A[2] = *(A + 2)--►| 'n' | 'o' | 't' | '\0'| '\0'|| 219 | +-----+-----+-----+-----+-----+| A[3] = *(A + 3)--►| 'd' | 'i' | 'e' | '\0'| '\0'|| | +-----+-----+-----+-----+-----+| +--------------------------------+ </code></pre> <p>A brief explanation about figure example. </p> <blockquote> <ul> <li>In figure <code>A</code> represents complete 2-D array starts with address 201, and</li> <li><code>&amp;A</code> gives address of complete 2-D array = 201</li> <li><code>*A = *(A + 0)</code> = <code>A[0]</code> points to first row = 201 </li> <li>Note value <code>A[0][0]</code> is <code>'f'</code> in my example, and <code>&amp;A[0][0]</code> gives address of <code>[0][0]</code> element = 201 </li> <li>Note <code>&amp;A[0][0]</code> is same as <code>*A</code>, because <code>&amp;A[0][0]</code> => <code>&amp;(*(*A))</code> => <code>&amp;**A</code> => <code>*A</code></li> </ul> </blockquote> <p>So all <code>A[0]</code>, <code>&amp;A</code>, <code>*A</code>, <code>A</code> are same but symmetrically different. </p> <p>To observe difference among the <code>A[0]</code>, <code>&amp;A</code>, <code>*A</code>, <code>A</code>. Type to print <code>sizeof()</code> information. e.g. </p> <pre><code> cout&lt;&lt;sizeof(A[0]) &lt;&lt;" "&lt;&lt;sizeof(&amp;A) &lt;&lt;" "&lt;&lt;sizeof(*A) &lt;&lt;" "&lt;&lt; sizeof(A); </code></pre> <p>Second try to print next location address using: </p> <pre><code> cout&lt;&lt;(A[0] + 1)&lt;&lt;" "&lt;&lt;(&amp;A + 1) &lt;&lt;" "&lt;&lt;(*A + 1)&lt;&lt;" "&lt;&lt;(A + 1); </code></pre> <p><em>For more detailed explanation, must read this <a href="https://stackoverflow.com/a/18364638/2455888">answer</a>.</em></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