InterviewSolution
Saved Bookmarks
| 1. |
An array MAT[30][10] is stored in the memory column wise with each element occupying 8 bytes of memory. Find out the base address and the address of element MAT[20][5], if the location of MAT[5][7] is stored at the address 1000. |
|
Answer» Base Address B No of rows m=30 Element size W=8 Lowest Row and column indices lr, lc=0 Address of Ith, jth element of array in column major order is: Address of MAT[I][J] = B + W(m(J - lc) + (I - lr)) MAT[5][7] = 1000 1000 = B + 8(30(7-0)+(5-0)) 1000 = B + 8(30(7)+(5)) 1000 = B + 8(210 + 5) 1000 = B + 8(215) 1000 = B + 1720 B = 1000 – 1720 B = -720 Base address is -720 Now address of MAT[20][5] is computed as: MAT[20][5] = -720 + 8(30(5 – 0) + (20 – 0)) = -720 + 8(30(5) + (20)) = -720 + 8(150 + 20) = -720 + 8(170) = -720 + 1360 = 640 |
|