how to create & Storage of two-dimensional array in memory in C

Two or More dimensional arrays works on table structure, as table stores values it stores values in table like structure (rows & Column).

• A two dimensional array has two subscripts.
(More dimension More Subscripts)
• First subscript is for row and second for column.
• The syntax for declaration of two dimensional array is
data_type array[row_size][column_size];

• Consider the example int pop[5][5];

Here aa is an integer array of size 5x5
i.e. total 25 elements.

• The array elements are represented using the subscript.
• While storing in memory, each dimension of the array is indexed from zero to it’s maximum size-1.
• The first subscript indicate row and second subscript indicates column.
• For eg. Consider an integer array of size 2x3 as

int X[2][3]={10,20,30,40,50,60};


The array b is represented in memory as

Col.0 Col.1 Col.2
row0 110 120 130
row1 140 150 160

Where,
x[0][0]=110
x[0][1]=120
x[0][2]=130
x[1][0]=140
x[1][1]=150
x[1][2]=160

No comments:

Post a Comment