Data Structure

Question

T[20][50] is a two dimensional array, which is stored in the memory along the row with each of its element occupying 4 bytes, find the address of the element T[15][5], if the element T[10][8] is stored at the memory location 52000.

Answer

Loc(T[I][J])
    =BaseAddress + W [( I – LBR)*C + (J – LBC)]
(where
W=size of each element = 4 bytes,
R=Number of Rows=20, C=Number of Columns=50)
Assuming LBR = LBC = 0
LOC(T[10][8])
      52000 = BaseAddress + W[ I*C + J]
      52000 = BaseAddress + 4[10*50 + 8]
      52000 = BaseAddress + 4[500 + 8]
      52000 = BaseAddress + 4 x 508
                   BaseAddress = 52000 2032
= 49968
LOC(T[15][5])= BaseAddress + W[ I*C + J]
      = 49968 + 4[15*50 + 5]
      = 49968 + 4[750 + 5]
      = 49968 + 4 x 755
      = 49968 + 3020
      = 5298

Sponsor Area

Some More Questions From Data Structure Chapter