Monday, January 6, 2025
HomeProgrammingTwo-Dimensional Array in C

Two-Dimensional Array in C

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.
See also  Difference Between Abstract Class and Interface in Java
RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x