100% found this document useful (1 vote)
39 views3 pages

Address of 2D Array Elements

Find Address of Element in 2D Array

Uploaded by

Sharad Sir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
39 views3 pages

Address of 2D Array Elements

Find Address of Element in 2D Array

Uploaded by

Sharad Sir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Find Addressing An Element Of An Array At A Particular Index

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

Consider an 3x4 Matrix(2D Array) to understand Row Major


and Coloumn Major :

Row Major System:


The address of a location in row major system: Elements Store in
Memory Row By Row

Address of A[ i ][ j ] = B+W*[ N*(i-Lr)+(j-Lc)]


Column Major System:
The address of a location in row major system: Elements Store in
Memory Column By Column

Address of A[i][j] =B+W*[(i-Lr)+M*(j-Lc)]


Where

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

usually number of rows and column of a matrix are given


like
A[10][15], A[5][2] but if it is given as
A[Lr......Ur][Lc.......Uc]

So in this case number of rows and columns will be calculated as

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]

Solution: We have to find the number of rows and column of matrix


x

M=(Ur-Lr)+1 => [10-(-15)]+1=> 26

N=(Uc-Lc)+1=> [40-15]+1 => 26

1) Row Major wise calculation of X[15][20]

B=1500, W=1 byte, I=15, J=20, Lr=-15, Lc=15,N=26


Address of A[I][J]= B+W*[N*(i-Lr)+(J-Lc)]

= 1500+1*[2*(15-(-15))+(20-15)]

=1500+1*[26*30+5]

=1500+785=2285

2) Column Major wise calculation of X[15][20]

B=1500, W=1; i=15,J=20,Lr=-15,Lc=15, M=26


X[15][20]= B+W*[(i-Lr)+M*(j-Lc)]

=1500+1*[(15-(15)+26*(20-15))]

=1500+1*[30+26+5]

=1500+1*(160)

=1660

You might also like