base address=1020 LB=1400 UB=1800 W=2 I=1700 address of A[I]=B+W*(I-LB) address of A[1700]=1020+2*(1700-1400) A[1700]=1020+600=1620
Q2.Calculate the address of x[4,3] in two dimensional array x[1....5,1....4] stored in row major order in the main memory.Base address to be 1000 and that each requires 4 words of storage.
x[4][3]=B+W(C(I-1)+(J-1)) x[4][3]=1000+4(4(4-1)+(3-1)) x[4][3]=1000+4(12+2)) x[4][3]=1000+56=1056
Q3.An array x[-15....10,15.....40]requires one byte of storage.If begining location is 1500 determine the location of x[15][20] using row major order.
number of column=40-15+1=26 x[15][20]=1500+1((15-(-15))*26+(20-15)) x[15][20]=2285
Q4.An array x[-15....10,15.....40]requires one byte of storage.If begining location is 1500 determine the location of x[15][20] using column major order.
number of rows=10-(-15)+1=26 x[15][20]=1500+1((15-(-15))+*26(20-15)) x[15][20]=1500+1(30+130) x[15][20]=1500+160 x[15][20]=1660
Q5.Each element of an array arr[15][20] requires W bytes of storage.If the address of arr[6][8] is 4440 and the base address at arr[1][1] is 4000,find the width W of each cell in the array arr[][] when the array is stored as column major wise.
4440=[4000+w((6-1)+15(8-1)) 4440=4000+w[5+105] 4440-4000=110w w=4400/110 w=4
0 Comments