Page 53 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 53

Fundamentals of Data Structures




                    Notes          The general form for declaring a single dimensional array is:
                                   data_type array_name[expression];
                                   where data_type represents data type of the array. That is, integer, char, float etc. array_name is
                                   the name of array and expression which indicates the number of elements in the array.


                                          Example: consider the following C declaration:
                                   int a[100];
                                   It declares an array of 100 integers.

                                   The amount of storage required to hold an array is directly related to its type and size. For a
                                   single dimension array, the total size in bytes required for the array is computed as shown
                                   below.

                                   Memory required (in bytes) = size of (data type) X length of array
                                   The first array index value is referred to as its lower bound and in C it is always 0 and the
                                   maximum index value is called its upper bound.




                                     Did u know?  The number of elements in the array, called its range is given by upper
                                     bound-lower bound.
                                   We store values in the arrays during program execution. Let us now see the process of initializing
                                   an array while declaring it.
                                    int a[4] = {34,60,93,2};
                                   int b[] = {2,3,4,5};
                                   float c[] = {-4,6,81,” 60};
                                   We conclude the following facts from these examples:

                                       If the array is initialized at the time of declaration, then the dimension of the array is
                                       optional.

                                       Till the array elements are not given any specific values, they contain garbage values.

                                          Example: Let us consider the following figure 4.1.
                                   (a)  Array DATA be a 6-element linear array of integers such that
                                   DATA[1]=247,  DATA[2]=56, DATA[3]=429, DATA[4]=135, DATA[5]=87,
                                   DATA[6]=156.
                                       The following figures 4.1 depict the array DATA.
                                                               Figure 4.1: Array  DATA










                                                                            (a)                                                             (b)

                                   Source:  http://www.csbdu.in/econtent/DataStructures/Unit1-DS.pdf



          46                                LOVELY PROFESSIONAL UNIVERSITY
   48   49   50   51   52   53   54   55   56   57   58