Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>"ARRAY ADDRESS AND POINTERS TO MULTIDIMENSIONAL ARRAYS"</h2> <p><strong>Lets we start with 1-D array first:</strong> </p> <ul> <li><p>Declaration <code>char a[8];</code> creates an array of 8 elements.<br> And here <code>a</code> is <strong>address of fist element</strong> but <strong>not address of array</strong>. </p></li> <li><p><code>char* ptr = a;</code> is correct expression as <code>ptr</code> is pointer to char and can address first element. </p></li> <li><p>But the expression <code>ptr = &amp;a</code> is <strong>wrong</strong>! Because <code>ptr</code> can't address an array.</p></li> <li><p><strong>&amp;a means address of array.</strong> Really Value of <code>a</code> and <code>&amp;a</code> are same but semantically both are different, One is address of char other is address of array of 8 chars. </p></li> <li><p><code>char (*ptr2)[8];</code> Here <code>ptr2 is pointer to an array of 8 chars</code>, And this time <code>ptr2=&amp;a</code> is a valid expression.</p></li> <li><p>Data-type of <code>&amp;a</code> is <code>char(*)[8]</code> and type of <code>a</code> is <code>char[8]</code> that simply decays into <code>char*</code> in most operation e.g. <code>char* ptr = a;</code></p> <p>To understand better read: <a href="https://stackoverflow.com/questions/15177420/what-does-sizeofarr-return/15177499#15177499">Difference between <code>char *str</code> and <code>char str[]</code> and how both stores in memory?</a> </p></li> </ul> <p><strong>Second case,</strong> </p> <ul> <li><p>Declaration <code>char aa[8][8];</code> creates a 2-D array of <code>8x8</code> size. </p></li> <li><p><strong>Any 2-D array can also be viewed as 1-D array in which each array element is a 1-D array</strong>. </p></li> <li><p><code>aa</code> is address of first element that is an array of 8 chars. Expression <code>ptr2 = aa</code> is valid and correct. </p></li> <li><p>If we declare as follows: </p> <pre><code>char (*ptr3)[8][8]; char ptr3 = &amp;aa; //is a correct expression </code></pre> <p><strong>Similarly,</strong><br> <code>moreThings</code> in your declaration <code>char moreThings[8][8];</code> contain address of fist element that is char array of 8 elements. </p> <p>To understand better read: <a href="https://stackoverflow.com/questions/17564608/what-does-the-array-name-mean-in-case-of-array-of-char-pointers/17661444#17661444">Difference between <code>char* str[]</code> and <code>char str[][]</code> and how both stores in memory?</a></p></li> </ul> <hr> <p><strong>It would be interesting to know:</strong> </p> <ul> <li><p><code>morething</code> is an address of 8 char array . </p></li> <li><p><code>*morething</code> is an address of first element that is <code>&amp;morething[0][0]</code>. </p></li> <li><p><code>&amp;morething</code> is an address of 2-D array of 8 x 8. </p> <blockquote> <p><strong>And address values of all above three are same but semantically all different.</strong> </p> </blockquote></li> <li><p><code>**morething</code> is value of first element that is <code>morething[0][0]</code>. </p> <p>To understand better read: <a href="https://stackoverflow.com/questions/15177420/what-does-sizeofarr-return/15177499#15177499">Difference between <code>&amp;str</code> and <code>str</code>, when <code>str</code> is declared as <code>char str[10]</code>?</a></p></li> </ul> <p><strong>Further more,</strong> </p> <ul> <li><code>void doThings(char thingsGoHere[8][8])</code> is nothing but void <code>doThings(char (*thingsGoHere)[8])</code> and thus accepts any array that is two dimensional with the second dimension being 8.</li> </ul> <hr> <p><strong>About type of variables in C and C++:</strong> (I would like to add in answer) </p> <ul> <li><strong>Nothing is pass by reference in C</strong> its C++ concept. If its used in C that means author talking about pointer variable. </li> <li>C supports <code>pass by Address</code> and <code>pass by value</code>. </li> <li><p>C++ supports <code>Pass by address</code>, <code>pass by value</code> and also <code>pass by Reference</code>.</p> <p>Read: <a href="https://stackoverflow.com/questions/17852911/assigning-int-value-to-an-address/17852936#17852936">pointer variables and reference variables</a></p></li> </ul> <p>At the end, </p> <ul> <li>Name Of an array is constant identifier not variable. </li> </ul>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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