Address of 2D Array Elements
Address of 2D Array Elements
In 2D Array
While storing the elements of 2D array in memory, these are allocated
contiguous memory locations. This storage arrangement can be Following
Ways :
Row Major
Column Major
B =
base address
I =
row Subscript of element whose address to be found
W =
Storage size of an element
Lr =
lower limit of ROW / start row index of matrix, if not given
then assume zero (0)
Lc = lower limit of COLUMN / start column index of matrix, if not
given then assume 0(Zero)
M = number of rows of the given matrix
N = number of column of the given matrix
rows(M)= (Ur-Lr)+1
column(N)=(Uc-Lc)+1
Example:
An array X[-15.......10,15.....40] required One byte of the storage
and the beginning location is 1500 so determine the location of
X[15][20]
= 1500+1*[2*(15-(-15))+(20-15)]
=1500+1*[26*30+5]
=1500+785=2285
=1500+1*[(15-(15)+26*(20-15))]
=1500+1*[30+26+5]
=1500+1*(160)
=1660