**Mathematical formula to find memory address of any element in 1D array :-
address of X[i] = base address of X + w*(i-l)
Here:-
X = 1D array
w = number of bytes occupied by element of array in memory.
i = index of element of array.
l =lower bound or lower limit of array (by default 0)
**Mathematical formula to find memory address of any 2D array :-
In 2D array, data elements are stored in following two types of order -
1. Row major order.
2. Coloumn major order.
1. Row major order.
2. Coloumn major order.
1.)Formula for row major order (by default) :-
Address of X[i][j] = base address of X + w*[n(i-lr)+(j-lc)]
2.)Formula for coloumn major order :-
Address of X[i][j] = base address of X + w*[(i-lr)+m(j-lc)]
Here,
X = given 2D array
w = number of memory bytes occupied by each element of array.
i = row index
j = coloumn index
lr = lower bound of row (lower limit)
lc = lower bound of coloumn (lower limit)
m = total number of rows exist in 2D array
And n = total number of coloumns exist in 2D array.
No comments:
Post a Comment