InterviewSolution
Saved Bookmarks
| 1. |
Each element of two-dimensional array (with 5 rows and 4 columns) is stored in one memory location. If A(1,1) is at location 2000, what is the address of A(4,4) ? The arrangement is row-major. Use a suitable formula for the calculation. |
|
Answer» A[5][4] => rows R=5, columns C=4 Let base address be B Given element width W=1 bytes and A[1][1]=2000 In Row major, A[I][J]=B+W(C(I=lr)+(j-lc)) where lr=lowest row and lc=lowest column A[1][1]=B+W(C(1-0)+(1-0)) 2000=B+1(4(1)+1) 2000=B+5 Base Address B=2000-5=1995 Using same formula A[4][4]=1995+1(4(4-0)+(4-0)) =1995+20 =2015 |
|