Mask-group

2-D Arrays in C



  • 2D Arrays(2-dimensional arrays) are represented in the form of rows and columns,also known as matrix.

  • It is also known as arrays of arrays or list of arrays.

Declaration:

data_type array_name[size1][size2];

Example:

int mat=[3][2];

Where 3 is a row number and 2 is a column number.

Initialization:

int arr[4][3]={{1,2,3},{4,5,6},{7,8,9},{0,1,2}};

Example of 2D Array:

Output:

arr[0][0] = 1

arr[0][0] = 2

arr[0][0] = 3

arr[0][0] = 2

arr[0][0] = 3

arr[0][0] = 4

arr[0][0] = 3

arr[0][0] = 4

arr[0][0] = 5

arr[0][0] = 4

arr[0][0] = 5

arr[0][0] = 6