If the starting address of an float array Arr[10][10] is 2000, what would be the memory address of the element Arr[5][6]?
Answers
Address=B+W[n(I-Lr) + (J-Lc )]
B is the base address
W is the element size in bytes
n is the number of columns
Lr is the first row number
Lc is the first column number
B=2000
Lr=0
Lc=0
W=4
n=10
I=5
J=6
using formula,
address= 2000+4[10(5–0) + (6–0)]
= 2000+4[50+6]
=2000+4[56]
=2000+224
=2224
The answer to he question (Assuming for a c Compiler) with 4 bytes for a float variable the memory address would actually increment by 4 bytes for each consecutive element of array.
So if the first address is 2000, then for every consecutive element, the address would actually increment by 4, thus,
[0][0]=2000 -[0][9]=2036
[1][0]=2040 -[1][9]=2076
[2][0]=2080 -[2][9]=2116
[3][0]=2120-[3][9]=2156
[4][0]=2160-[4][9]=2196
[5][0]=2200 [5][1]=2204 [5][2]=2208 [5][3]=2212 [5][4]=2216 [5][5]=2220
Therefore, the answer to your question is [5][6]=2224