

An array consisting of two subscripts is known as a two-dimensional array. These are often known as an array of the array. In two-dimensional arrays, the array is divided into rows and columns. These are well suited to handle a table of data. In a 2-D array, we can declare an array as :
Declaration:-
Syntax: data_type array_name[row_size][column_size];
Ex:- int arr[3][3];
where the first index value shows the number of the rows and the second index value shows the number
of the columns in the array.
Initializing two-dimensional arrays:
Like the one-dimensional arrays, two-dimensional arrays may be initialized by following their declaration with a list of initial values enclosed in braces.
Ex: int a[2][3]={0,0,0,1,1,1}; initializes the elements of the first row to zero and the second row to one. The initialization is done row by row.
above statement can also be written as
int a[2][3] = {{ 0,0,0},{1,1,1}};
by surrounding the elements of each row by braces.
We can also initialize a two-dimensional array in the form of a matrix as shown below
int a[2][3]={
{0,0,0},
{1,1,1}
};
When the array is completely initialized with all values, explicitly we need not specify the size of the first dimension.
Ex: int a[][3]={
{0,2,3},
{2,1,2}
};
If the values are missing in an initializer, they are automatically set to zero.
Ex: int a[2][3]={
{1,1},
{2}
};
Will initialize the first two elements of the first row to one, the first element of the second row to two, and all other elements to zero.
Recommended Questions
Recommended Files from Library
Useful Files
Users Joined





An array consisting of two subscripts is known as a two-dimensional array. These are often known as an array of the array. In two-dimensional arrays, the array is divided into rows and columns. These are well suited to handle a table of data. In a 2-D array, we can declare an array as :
Declaration:-
Syntax: data_type array_name[row_size][column_size];
Ex:- int arr[3][3];
where the first index value shows the number of the rows and the second index value shows the number
of the columns in the array.
Initializing two-dimensional arrays:
Like the one-dimensional arrays, two-dimensional arrays may be initialized by following their declaration with a list of initial values enclosed in braces.
Ex: int a[2][3]={0,0,0,1,1,1}; initializes the elements of the first row to zero and the second row to one. The initialization is done row by row.
above statement can also be written as
int a[2][3] = {{ 0,0,0},{1,1,1}};
by surrounding the elements of each row by braces.
We can also initialize a two-dimensional array in the form of a matrix as shown below
int a[2][3]={
{0,0,0},
{1,1,1}
};
When the array is completely initialized with all values, explicitly we need not specify the size of the first dimension.
Ex: int a[][3]={
{0,2,3},
{2,1,2}
};
If the values are missing in an initializer, they are automatically set to zero.
Ex: int a[2][3]={
{1,1},
{2}
};
Will initialize the first two elements of the first row to one, the first element of the second row to two, and all other elements to zero.

