C Programming • C17 baseline, standards-specific features labeled
Multidimensional Arrays
Represent tables with arrays of arrays and keep the number of columns part of the function type.
A two-dimensional C array is an array whose elements are themselves arrays. Elements are stored row by row. When passing a two-dimensional array to a function, the compiler needs the column count to calculate each row address.
Example
#include <stddef.h>
#include <stdio.h>
int main(void) {
int grid[2][3] = {{1, 2, 3}, {4, 5, 6}};
for (size_t row = 0; row < 2; ++row) {
for (size_t column = 0; column < 3; ++column) {
printf("%d ", grid[row][column]);
}
putchar('\n');
}
return 0;
}
What to expect
Prints two rows: 1 2 3 and 4 5 6.
Key idea: Keep row and column bounds explicit; a pointer-to-pointer is not automatically interchangeable with a two-dimensional array.