Page 74 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 74

Unit 5: Pointers




          We can legally do name[3][4] and Aname[3][4] in C.                                    Notes
          However
               Aname is a true 200 element 2D char array.

               access elements via
               20*row + col + base_address
               in memory.
               name has 10 pointer elements.



             Did u know? If each pointer in name is set to point to a 20 element array then and only then
             will 200 chars be set aside (+ 10 elements).


          The advantage of the latter is that each pointer can point to arrays be of different length.
          Consider:
           char *name[] = { “no month”, “jan”,
                                       “feb”, ... };
                          char Aname[][15] = { “no month”, “jan”,
                                       “feb”, ... };

                               Figure 5.5: 2D Arrays and Arrays of Pointers











































                                           LOVELY PROFESSIONAL UNIVERSITY                                   67
   69   70   71   72   73   74   75   76   77   78   79