I know that multidimensional arrays are allocated contiguously, so int[4][3] arr; will allocate 12 int cells in a row.
My first question is, given that C does not keep track of the lengths of arrays, how does it know the proper arithmetic needed to convert the two coordinate access pattern into the single coordinate memory address? E.g., if
arr == 0x? // some memory address
Then
&arr[2][1] == 0x? + 3 * 2 int cells + 1 int cell.
Where are the 3 pulled from?
My second question is when arrays are allocated on the heap, are they still allocated in the same contiguous manner? Or is it implemented as an array of pointers, which dereference to one dimensional arrays?
int[4][3] arr[sic]. That is crucial, but the first dimension is not, perhaps that is what you are confusing. You can declare a functionfoo(int bar[][3])which does need to know the first dimension to work, but of course it needs to know the limit in some way..