Page 76 - C++
P. 76

OR
                             (1 Mark for correct loop)
                             (2 Marks for swapping elements)

                      (c)    An array S[10] [30] is stored in the memory along the column with each of  (3)
                             its element occupying 2 bytes. Find out the memory location of S[5][10], if
                             element S[2][15] is stored at the location 8200.

                                                                OR
                             An array A[30][10] is stored in the memory with each element requiring 4
                             bytes of storage ,if the base address of A is 4500 ,Find out memory
                             locations of A[12][8], if the content is stored along the row.


                      Ans.  OPTION 1:
                             ASSUMING LBR=LBC=0
                             W=2 BYTES, NUMBER OF ROWS(M)=10, NUMBER OF
                             COLUMNS(N)=30
                             LOC(S[I][J]) = B +(I + J*M)*W
                             LOC(S[2][15]) = B +(2+15*10)* 2
                             8200 = B + (152*2)
                             B = 8200 - 304
                             B = 7896
                             LOC(S[5][10]) = 7896 +(5+10*10)* 2
                             = 7896 + (105*2)
                             = 7896 + 210
                             = 8106

                             OPTION 2:
                             ASSUMING LBR=2,LBC=15 AND B = 8200
                             W=2 BYTES, NUMBER OF ROWS(M)=10, NUMBER OF
                             COLUMNS(N)=30
                             LOC(S[I][J]) = B +((I-LBR) + (J-LBC)*M)*W
                             LOC(S[5][10])= 8200 + ((5-2) + (10-15)*10)*2
                             = 8200 + (3 + (-5)*10) * 2
                             = 8200 + (3 + (-50)) * 2
                             = 8200 + (3 – 50) * 2
                             = 8200 + (-47) * 2
                             = 8200 – 94
                             = 8106

                                                                OR

                             Loc of A[12][8]= B+W*(N*(I-LBR)+(J-LBC))
                                                         =4500+4*(10*12+8)
                                                          = 4500 4*(128)
                                                          =4500 + 512
                                                          = 5012


                                                             12
   71   72   73   74   75   76   77   78   79   80   81