Computer Science, asked by TbiaSamishta, 1 year ago

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

Answered by Apc77
0
Hey mate !!
here's your answer

Address of [I,J]th element in C++ is given by:

Address=B+W[n(I-Lr) + (J-Lc )]

where,

B is base address

W is element size in bytes

n is number of columns

Lr is first row number

Lc is first column number..

In this question,

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

Therefore, address of [5][6] is 2224 in Row-Major Implementation.

For column-major implementation, you should use the formula:

Address of [I,J]= B+W[r(J-Lc)+( I-Lr)]

where, r is number of rows in an array.

Thanks.

Answered by aqibkincsem
3

"To calculate the memory address of Arr[5][6] :

if your first address is 2000 then for each consecutive element the address would increment by 4 (considering it is a float variable) so


[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


so the answer is [5][6]=2224 Therefore the address of the memory location Arr[5][6] is 2224."

Similar questions