MULTI DIMENSIONED ARRAYS
Multi-dimensioned arrays have two or more index values which
specify the element in the array.
multi[i][j]
In the above example, the first index value i specifies a row index, whilst j specifies a column index.
Declaration and calculations
int m1[10][10]; static int m2[2][2] = { {0,1}, {2,3} }; sum = m1[i][j] + m2[k][l];
NOTE the strange way that the initial values have been assigned to the two-dimensional array m2. Inside the braces are,
{ 0, 1 }, { 2, 3 }
Remember that arrays are split up into row and columns. The first is the row, the second is the column. Looking at the initial values assigned to m2, they are,
m2[0][0] = 0 m2[0][1] = 1 m2[1][0] = 2 m2[1][1] = 3
EXERCISE C13
Given a two dimensional array, write a program that totals all
elements, printing the total.
CLASS EXERCISE C14
What value is assigned to the elements which are not assigned
initialised.
©Copyright B Brown. 1984-1999. All rights reserved.