I'm just wondering about two dimensional arrays I'm on chapter 14 (Dynamic Memory Allocation) of Alex Allains book and we are learning about multidimensional arrays and pointer arithmetic
one thing I don't get is why do you have to ONLY include the second size of the array and not the first for example
1 2 3 4 5 6 7
void PrintArray(int array[][4){
// do something
}
and if that's possible how come you just can't declare an array in the first place with only the second size mentioned for example
1 2
int ray[][4];
if anyone could explain this in layman's terms(if possible) that would be great
When you declare a 2d array, the compiler needs to know both dimensions*. 2d arrays are actually stored as 1d arrays using the formula for a position: pos = row * NumCols + col, where row and col are the 2d position.
When an array is sent to a function, the compiler knows the size of it, so only needs the NumCols in order to implement the formula above.
* Unless you initialise it directly, in which case the compiler can count them.
Why don't you skip this chapter in the book. Pointers and dynamic arrays are a thing of the past. In modern C++ we have the STL which makes things much easier.