Two Dimensional Arrays
A 2D array is an array of arrays, stored row by row. Declare with two sizes and loop with nested loops.
Example
int m[2][3] = {{1, 2, 3}, {4, 5, 6}};
int sum = 0;
for (int r = 0; r < 2; r++)
for (int c = 0; c < 3; c++) sum += m[r][c];
printf("%d %d\n", sum, m[1][2]);
printf("%zu\n", sizeof(m) / sizeof(m[0][0]));Result
21 6 6
Exercise
Declare 2 rows, 3 columns.
int m[2]3];
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.