A two-dimensional array in C is a matrix-like structure to store data in rows and columns.
Declaration:
c
data_type array_name[rows][columns];
Example:
c
int matrix[3][3]; // 3x3 integer array
Initialization:
c
int matrix[2][2] = {
{1, 2},
{3, 4}
};
Access Elements:
c
printf("%d", matrix[1][0]); // Outputs 3
Loop Example:
c
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
printf("%d ", matrix[i][j]);
}
}
Key Points:
- Indexed as
array[row][column]
. - Rows and columns are zero-based.