1.

An array Arr[15][35] is stored in the memory along the column with each element occupying 8 bytes. Find out the base address and address of the element Arr[2][5], if the location Arr[5][10] is stored at the address 4000.

Answer»

Arr[15][35]

No. of Rows(i.e., R) = 15

No. of Cols(i.e., C) = 35

Element size(W) = 8 bytes 

Arr[I][J] = Arr[2][5] => I=2, J=5

Address of Arr[5][10] = 4000

Base Address (B) =? 

Lowest Row (i.e., lr) = 0

Lowest Col (i.e., lc) = 0

Formula to calculate address in Column Major arrangement is: 

Arr[P][Q] = B + W[(P - lr ) + R(Q - lc )] 

Arr[5][10] = B + 8((5 – 0) + 15(10 – 0)) 

4000 = B + 8(155) 

4000 = B + 1240 

=> B = 4000-1240= 2760

Parallely, Arr[I][J] = B + W[(I - lr ) + R(J - lc )] 

Arr[2][5] = 2760 + 8[(2 – 0) + 15(5 – 0)]

= 2760 + (8 x 77)

= 2760 + 616

= 3376



Discussion

No Comment Found

Related InterviewSolutions