Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In short: The compiler doesn't need the dimension, because a array <strong>decays</strong> to a pointer. But any additional dimension is needed by the compiler, to calculate the correct location in memory.</p> <p>At first you need to know that an array in C/C++ is a linear continuous object in memory. Which is very efficient.</p> <p>Because an array in C/C++ is a linear continuous object in memory, an array will <strong>decay</strong> to a pointer. Copying the complete array will be a waste of time and memory and is not requiered. A pointer is anything needed to go through the array. To go through the array you can take the increment-operator or any calculation which evaluates to a valid address in the array. You can set a delimiter in the array itself i.e. <em>'\0'</em> in a String, or pass the length to the function seperatley to tell your code where the end of the array is.</p> <p>With multi-dimensional arrays the thing is a little bit more complicated. A multi-dimesional array is still only a linear continuous object in the memory! But the compiler needs the information about the additional dimensions to <strong>calculate</strong> to correct position in memory, imagine the following:</p> <pre><code>char array[10][10]; // 0 - 99 </code></pre> <p>correct:</p> <pre><code>// formal argument tells your compiler, that each column is 10 elements long funca(int array[10][10]) { // access to element 25 (2 * 10 + 4, the 10 is known through your formal argument, remember that an array is null based) array[2][3] = 'x'; } </code></pre> <p>wrong:</p> <pre><code>// formal argument tells your compiler, that ech colum is 5 elements long funcb(int array[10][5]) { // access to element 15 (2 * 5 * + 4, the 5 is known through your formal argument, remember that an array is null based) array[2][3] = 'x'; } </code></pre> <p>A note (or warning): Arrays in Java, especiallay (irregular) multi-dimensional arrays are completely different.</p>
    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. 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