Page 89 - 6437
P. 89

Passing arrays to functions       You can pass to the function a pointer to an array
                                                    by specifying the array's name without  an


                                                                           index.



                                         Return array from a               C allows a function to return an array.
                                 function

                                         Pointer to an array               You can generate a pointer to the first element of
                                                                   an  array  by  simply  specifying  the  array    name,  without
                                                                   any index.



                          MultidimensionalArrays
                          C programming language allows multidimensional arrays. Here is the general form of a
                   multidimensional array declaration:


                 type name[size1][size2]...[sizeN];

                          For example, the following declaration creates a three-dimensional integer  array:
                            int threedim[5][10][4];


                          Two-dimensionalArrays
                          The  simplest  form  of  multidimensional  array  is  the  two-dimensional  array.  A  two-
                   dimensional array is, in essence, a list of one-dimensional arrays. To declare a two-dimensional
                   integer array of size [x][y], you would write something as follows:
                          Where type can be any valid C data type and arrayName will be a valid C identifier. A
                   two-dimensional  array  can  be  considered  as  a  table  which  will  have  x  number  of  rows  and  y

                 type arrayName [ x ][ y ];
                   number of columns. A two-dimensional array a, which contains three rows and four columns can
                   be shown as follows:











                          Thus, every element in the array a is identified  by an element name of the  form a[ i ][ j ],
                   where ‘a’ is the name of the array, and ‘i' and ‘j’ are the subscripts that uniquely identify each
                   element in ‘a’.









                                                                                                      92
   84   85   86   87   88   89   90   91   92   93   94