Multidimensional Arrays in C
Multidimensional arrays nest the idea: int grid[3][4]; is three rows of four ints, one flat contiguous block in row-major order. Indexing grid[r][c] walks rows then columns, and nested loops (outer rows, inner columns) traverse naturally.
Only the first dimension may be deduced, and function parameters must declare all but the first (void f(int m[][4])) — another reason dynamic grids often become flat malloc'd blocks with manual row*cols+c indexing.
Rows of rows, one block
int grid[3][4]; holds 12 ints contiguously — grid[1][0] sits right after grid[0][3] in memory.
Nested loop traversal
Outer rows, inner columns visits every cell exactly once — the grid-processing standard shape.
Partial deduction only
int g[][2] = {{1,2},{3,4}}; deduces 2 rows, but the column count must always be spelled out.
Signatures pin dimensions
Parameter int m[][4] hard-codes 4 columns — mismatched widths won't compile.
#include <stdio.h> int main(void) { int grid[2][3] = {{1, 2, 3}, {4, 5, 6}}; int sum = 0; int r, c; for (r = 0; r < 2; ++r) { for (c = 0; c < 3; ++c) { sum += grid[r][c]; } } printf("%d\n", sum); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.