Note that there are some explanatory texts on larger screens.

plurals
  1. POArray to pointer decay and passing multidimensional arrays to functions
    primarykey
    data
    text
    <p>I know that an array decays to a pointer, such that if one declared</p> <pre><code>char things[8]; </code></pre> <p>and then later on used <code>things</code> somewhere else, <code>things</code> is a pointer to the first element in the array.</p> <p>Also, from my understanding, if one declares</p> <pre><code>char moreThings[8][8]; </code></pre> <p>then <code>moreThings</code> is <em>not</em> of type pointer to char but of type "array of pointers to char," because the decay only occurs once.</p> <p>When <code>moreThings</code> is passed to a function (say with prototype <code>void doThings(char thingsGoHere[8][8])</code> what is actually going on with the stack?</p> <p>If <code>moreThings</code> is not of pointer type, then is this really still a pass-by-reference? I guess I always thought that <code>moreThings</code> still represented the base address of the multidimensional array. What if <code>doThings</code> took input <code>thingsGoHere</code> and itself passed it to another function?</p> <p>Is the rule pretty much that unless one specifies an array input as <code>const</code> then the array will always be modifiable?</p> <p>I know that the type checking stuff only happens at compile time, but I'm still confused about what technically counts as a pass by reference (i.e. is it only when arguments of type pointer are passed, or would array of pointers be a pass-by-reference as well?)</p> <p>Sorry to be a little all over the place with this question, but because of my difficulty in understanding this it is hard to articulate a precise inquiry.</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.
 

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