Page 308 - Computer science 868 Class 12
P. 308

LB :  Lower Bound of subscript (if not specified, it will be “0”) : 0
              I   :  Subscript of the element whose address is to be calculated.
              Let us do some more examples given below.

                1.    Given the base address of an array B[1200…..1800] as 980 and size of each element is 4 bytes in the memory.
                    Find the address of B[1340].
               Ans.  The given values are: B = 1340, LB = 980, W = 4, I = 1340
                     Address of A [ I ] = B + W * ( I - LB )
                    = 980 + 4 * (1340 - 1200)

                    = 980 + 4 * 140
                    = 980 + 280
                    = 1260
                2.   An array ar[900 …. 2505] is stored at the base address 1500. Each element of the array occupies 8 bytes in the
                    memory. Find the address of :
                    a.  ar[1100]
                    b.  ar[2420]

               Ans.  a.  The given values are: B = 1500, LB = 900, W = 8, I = 1100
                      Address of A [ I ] = B + W * ( I - LB )

                      = 1500 + 8 * (1100 - 900)
                      = 1500 + 8 * 200
                      = 1500 + 1600
                      = 3100

                    b.  The given values are: B = 1500, LB = 900, W = 8, I = 2420
                      Address of A [ I ] = B + W * ( I - LB )
                      = 1500 + 8 * (2420 – 900)

                      = 1500 + 8 * 1520
                      = 1500 + 12160
                      = 13660

              9.6.2 Address Calculation in Two-Dimensional Arrays
                                                                  Column Index
                                                         0        1        2        3

                                                   0     10       22       94       87
                                             Row
                                            index  1    100      104      108      112
                                                   2    100      104      108      112
              The address of an element in two-dimensional arrays can be calculated in two different forms:
              a.  Row Major System:
                Address of A [ I ][ J ] = B + W * [ N * ( I – Lr ) + ( J – Lc ) ]

                                         1    2   3    4   5    6   7    8   9   10   11  12
                Arranged in Row major wise




                306306  Touchpad Computer Science-XII
   303   304   305   306   307   308   309   310   311   312   313