A 2D array is a grid: rows and columns of boxes. Two indexes pick one cell — and memory still stores it all in one line.
1 Declaration
int m[2][3] reserves 2 rows of 3 columns — six boxes in total.
2 Two indexes
m[r][c]: the first bracket picks the row, the second the column. Both count from 0.
3 Nested loops
One loop per dimension: the outer walks rows, the inner walks each row's cells.
4 Row-major memory
C lays the grid out row after row: m[0][0], m[0][1], m[0][2], m[1][0], ...
A grid of boxes
Declaration1int m[2][3] reserves 2 rows of 3 columns — six boxes in total. Two indexes2m[r][c]: the first bracket picks the row, the second the column. Both count from 0.
Nested loops3One loop per dimension: the outer walks rows, the inner walks each row's cells. Row-major memory4C lays the grid out row after row: m[0][0], m[0][1], m[0][2], m[1][0], ... 4 building blocks make up A grid of boxes
Six cells for a 2×3 grid — play the script and watch row 1 continue straight after row 0. Drag to orbit.
Drag to orbit the scene. Press Play to watch memory in action.
Press play — the outer loop picks a row, the inner loop walks every cell in it.
preprocessThe preprocessor pastes in stdio.h.
Memory
no variables yet — press play
Console
output appears as the program runs…
Row first, column second — which cells are these?
Your predicted output — one line per console line
Hint: The first bracket picks the row, the second the column — both start at 0, so m[1][0] is row 1, column 0.
Click a term, then click its meaning to lock the pair.
5 conceptsTap a card to expand ?int m[2][3]drops into place
?m[1][2]drops into place
?row-majordrops into place
?nested loopsdrops into place
?m[r][c]drops into place
01int m[2][3] is 2 rows × 3 columns — six boxes, one name.
02m[r][c]: row first, column second, both starting at 0.
03Memory is one straight line — rows are simply laid end to end.
04Nested loops visit every cell: outer for rows, inner for columns.
05The last cell of int m[2][3] is m[1][2] — never m[2][3].