MULTI-DIMENSIONAL ARRAYS

Multi dimensional array is an array in which more than one row and one column is present.Chess board is an example to two dimensional array.Two dimensional array use to indices to pinpoint an individual element of the array.This is very similar to what is called "algebraic notation ",commonly used in chess circles to record games and chess problems. '

Multi-Dimension Array Declaration

The syntax is as follows:

datatype array_name[Size1][SIZE2];

in the above statement,datatype is the name of some type of data,such as int,char.Size1 and Size2 are the size of an array's first(row) and second(column) dimension,respectively.8-by-8 array of integers is similar to a chessboard.Remember,because C arrays are zero-based,the indices on each side of the chessboard array run 0 through 7,rather than 1 to 8.

int chessboard[8][8];

Initialization of Two-dimensional arrays

If you have an m x n array then it will have  m*n  elements and will require m*n*elements size bytes of storage.To allocate storage for an array you must reserve this amount of memory.The element of two-dimensional array are stored row wise .
int tab[3][3]={1,2,3,4,5,6,7,8,9};
It means that elements
table[0][0] =1;
table[0][1] =2;
table[0][2] =3;
table[1][0] =4;
table[1][2] =5;
table[1][3] =6;
table[2][0] =7;
table[2][1] =8;
table[2][2] =9;

0 comments:

Post a Comment