Page 75 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 75

Fundamentals of Data Structures




                    Notes          5.2.2 Static Initialisation of Pointer Arrays

                                   Initialisation of arrays of pointers is an ideal application for an internal static array.
                                   some_fn()
                                                  { static char *months = { “no month”,
                                                                               “jan”, “feb”,
                                                                               ...};
                                                                }
                                   static reserves a private permanent bit of memory.




                                      Task  Write a C program to read through an array of any type using pointers.

                                   Self Assessment

                                   Fill in the blanks:

                                   6.  .............................. are a data representation that will cope efficiently and conveniently with
                                       variable length text lines.
                                   7.  A 2D array is really a .............................. array, each of whose elements is itself an array.

                                   8.  C needs to know how many .............................. in order that it can jump from row to row in
                                       memory.
                                   9.  Initialisation of arrays of pointers is an ideal application for an internal ..................... array.

                                   10.  .............................. elements are stored row by row.

                                   5.3 Records and Record Structures

                                   As we studied already that the collections of data are frequently organized into a hierarchy of
                                   field, records and files. Specifically a record is a collection of related data items, each of which is
                                   called a field or attribute, and a file is a collection of similar records. Each data item itself may be
                                   a group item composed of sub items; those items which are indecomposable are called elementary
                                   items or atoms or scalars. The names given to the various data items are called identifiers.
                                   As we know that a record is a collection of data items, it differs from a linear array in the
                                   following way,
                                   (a)  A record may be a collection of non-homogeneous data; i.e. the data items in a record may
                                       have different data types.

                                   (b)  The data items in a record are indexed by attribute names, so there may not be a natural
                                       ordering of its elements.
                                   Under the relationship of group item to sub item, the data items in a record form a hierarchical
                                   structure which can be described by means of “level” numbers. Let we understand through the
                                   following examples.

                                          Example:

                                   Consider a hospital keeps a record on each newborn baby who contains the following data
                                   items: Name, Sex, Birthday, Father, and Mother. Assume that Birthday is a group item with sub



          68                                LOVELY PROFESSIONAL UNIVERSITY
   70   71   72   73   74   75   76   77   78   79   80