Two dimensional array (2-D array) is also called Matrix |
|
General form of 2-D array is: |
|
data_type array_name[row_size][column_size]; |
|
Example: |
int marks [4][2] |
|
Different ways of Initialization of a 2-Dimensional Array: |
|
int table [2][3]={0,0,0,1,1,1}; |
initialization done by row. |
|
int table[2][3]={{0,0,0},{1,1,1}}; |
surrounding the elements of each row by braces. |
|
int table[2][3]={{0,0,0,}, |
initialization as matrix. |
|
An example program that stores roll number and marks obtained by a student side by side in Matrix: |
|
 |
|
Explanation |
|
There are two parts of the program. In the first part a for loop will read the values of rollno. and marks, whereas in the second part another loop will print these values. |