TCS
Company
In a two-dimensional array, X (7, 9), with each element occupying 8 bytes of memory, with the address of the first element X (1, 1)=3000; find the starting address of the element at X (5,8)
Read Solution (Total 3)
-
- there are two methods to solve such question one is formula based and other is direct i am discussing the answer by both methods-->>
1st method::
use the formula>>> x[i,j]=(base-address)+word*(n*(i-1)+j-1)
here, base=3000,m=7,n=9,w=8,i=5,j=8
x[5,8]=3000+8*(9*(5-1)+8-1)
=3000+8*43
=3344
2nd(direct) method:-
since we have to find the starting address for x[5,8]
means all the 4 rows of array are occupied before x[5,8]
and 7 elements in 5th rows are also occupied before x[5,8]
no. of elements in each row=no. of columns=9(here)
so no. of elements in 4 rows=4*9=36
no. of elements in 5th rows=7(before x[5,8])
hence total elements before x[5,8]=36+7=43
size of 1 element=8 bytes
size of 43 elements=43*8=344
now, starting address of x[5,8]= base + size of 43 elements
=3000 + 344
=3344 - 13 years agoHelpfull: Yes(24) No(1)
- 3352
your calculation is wrong taniya.... - 13 years agoHelpfull: Yes(2) No(4)
- 3000+8*(9*(5-1)+8-1)=4784
base add+word*(no of column*(X-1)+(Y-1)) if matrix is in row major form - 13 years agoHelpfull: Yes(1) No(1)
TCS Other Question