InterviewSolution
Saved Bookmarks
| 1. |
An array T[50][20] is stored in the memory along the column with each element occupying 4 bytes. Find out the base address and address of the element T [30][15], if the element T[25][10] is stored at the memory location 9800. |
|
Answer» T[50][20] No. of Rows(i.e., R) = 50 No. of Cols(i.e., C) = 20 Element size(W) = 4 bytes T[I][J] = T[30][15] => I=30, J=15 Address of T[25][10] = 9800 Base Address (B) =? Lowest Row (i.e., lr) = 0 Lowest Col (i.e., lc) = 0 Formula to calculate address in Column Major arrangement is: T[P][Q] = B + W[(P - lr) + R(Q - lc )] T[25][10] = B + 4((25 – 0) + 50(10 – 0)) 9800 = B + 4(525) (∵ T[25][10] = 9800 given) 9800 = B + 2100 => B = 9800 – 2100 = 7700 Parallely, T[I][J] = B + W[(I - lr ) + R(J - lc )] T[30][15] = 7700 + 4[(30 – 0) + 50(15 – 0)] = 7700 + (4 x 780) = 7700 + 3120 = 10820 |
|