Two dimensional array is used to store the data in the matrix form.
Syntax:
datatype arrayname[row_size][column_size];
Declaration of Two Dimensional Array:
Example: int matrix[3][2];
The above declaration is a two dimensional array consisting of 3 rows and 2 columns and the total number of element stored in this array are 3*2 i.e., 6.
Construction of Two Dimensional Array:
Creating a two dimensional array is same as one dimensional array
Syntax:
datatype arrayname[][]; //(declaration of array)
arrayname=new datatype[a][b]; //(allocating memory to an array)
Where a=row_size; b=column_size;
Example:
int matrix[][];
matrix=new int[3][2];
The other way of creating two dimensional array:
Syntax:
datatype arrayname[]=new datatype[a][b];
Example:
int matrix=new int[3][2];
Initializing a Two Dimensional Array:
Two dimensional array can also be initialized with a list of values while declaring.
Syntax:
datatype arrayname[][]={{value_row1_column1,value_row1_column2, ………….},{value_row2_column1,value_row2_column2, ………..}};
Example:
int array[][]={{3,3},{2,2}};