Addresses of Two Dimensional arrays can be calculated by using
1. Row Major representation
2. Column major Representation
1. Row Major representaion: Let X be an array of M Rows and N Columns
Address Location (X [i, j]) = Base Adress of X + S [N (i-LBofrow) + (j -LBofCol)]
i and j indicates index value of the element whose address you want to search.
Base Adress of X is the starting address of the given array.
S is the memory word required to store given array’s element.
LBofrow is Lower Boundary of Rows
LBofCol is Lower Boundary of Columns
Example :
Rows: 2 Columns : 3
3 | 4 | 5 |
2 | 1 | 6 |
0 1 2
Let base address be 200
w be 2 bytes(int)
Address of x[1,0]=200+2[3[1-0]+[0-0]]
=200+2[3-0]
=200+6
=206
2 Column Major Representation
Address Location (X [i, j]) = Base Adress of X + S [(j- LBofrow) +M(i - LBofCol)]