Page 78 - DCAP407_DATA_STRUCTURE
P. 78

Unit 4: Pointers



               Then, the elements of the matrix d are stored in memory row-wise as shown in figure 4.2:

                                               Figure 4.2: Array of Pointers



















               By using array of pointers, you can declare d as:
               int  *d[3];
               Here, d is an array of pointers, d[0] gives the address of Row 0, d[1] gives the address of Row 1, and
               d[2] gives the address of Row 2. Now, d[0]+0 will give the address of the element in the 0  row and 0
                                                                                                 th
                                                                                       th
               column, d[0]+1 will give the address of the element in the 0  row and 1  column and so on.
                                                               th
                                                                        st
               In general, the address of the element in the i  Row and j Column is given by:
                                                             th
                                                   th
                       d[i]+j
               The element in the i  Row and j Column can be accessed using “*” (indirection operator) by specifying
                                         th
                               th
               *(d[i]+j).
               4.6   Records and Record Structures
               Usually, collection of data is organized into hierarchy of fields, records, and files. A file is a collection of
               similar records and a record is a collection of related data items, where each data item is called a field or
               an attribute. Each data item can be a group item composed of sub items. The items which cannot be
               decomposed are called elementary items, scalars or atoms. Identifiers are used to refer to the data types,
               variables, and functions.
               A record is a collection of data items that differs from a linear array in the following ways:
               1.   A record can be a collection of non-homogenous data (data items with different data types).
               2.   In a record, data items are indexed by attribute names.  Therefore, there may not be a natural
                    ordering of the elements.
               Under the relationship of  a  group item to sub item, “level” numbers can be  used to  describe the
               hierarchical structure of the data items in a record, as shown in the following example:


                                Consider a kindergarten school maintaining a record of the admission application
                                it receives. The record contains the following data items: name, gender, date of
                                birth, father’s name, mother’s name, and address. Further, date of birth is a group
                                item with sub items month, day, and year, Father and Mother group items will
                                have sub items Name and Age, and Address group items will have sub items
                                Dno, Road, and Area.

                                The structure of the record can be as follows:
                                1 Application
                                    2 Name                                  //data item



                                        LOVELY PROFESSIONAL UNIVERSITY                           71
   73   74   75   76   77   78   79   80   81   82   83