Two Dimensional Array:-
A two dimensional array is suitable
for processing table. For two dimensional array we use two subscripts enclosed
in square brackets. Two dimensional arrays are declared in the same manner as
one dimensional array, except that a separate pair of square brackets is
required for each additional dimension of the array. To declare a two
dimensional array, the first value we specify indicates the number of rows and
the second value the number of columns.
Syntax:- data_type
array_var [index] [index];
Ex:- int
x[3][5];
Is the declaration of an array x which
has 3 rows and 5 columns.
Note:-
All arrays, number matter how
many dimensions they have, are stored sequentially in memory.
Initializing a two dimensional Array:-
While initializing a two dimensional
array, we should enclosed each row in braces.
Ex:- int
magic[5][5] = {
{17,24,1,8,15},
{23,5,7,14,16}
{4,6,13,2,22}
{10,12,19,21,3}
{11,18,25,2,9}
};
No comments:
Post a Comment