Professional Documents
Culture Documents
The simplest way to initialize an array is by using the index of each element. We can
initialize each element of the array by using the index. Consider the following example.
1.marks[0]=80;//initialization of array
2.marks[1]=60;
3.marks[2]=70;
4.marks[3]=85;
5.marks[4]=75;
Few keynotes:
Arrays have 0 as the first index, not 1. In this example, mark[0] is the first
element
If the size of an array is n, to access the last element, the n-1 index is used. In
this example, mark[4]
Output:
data_type array_name[rows][columns];
int twodimen[4][3];
There are two ways to initialize a two Dimensional arrays during declaration.
int arr[4][3]={{1,2,3},
{2,3,4},
{3,4,5},
{4,5,6}};
1. int disp[2][4] = { {10, 11, 12, 13}, {14, 15, 16, 17} };OR
2. int disp[2][4] = { 10, 11, 12, 13, 14, 15, 16, 17};
Although both the above declarations are valid, I recommend you to use the first
method as it is more readable, because you can visualize the rows and columns of 2d
array in this method.