Page 92 - 6437
P. 92

Way-2
                          Formal parameters as a sized array:

                 void myFunction(int param[10])
                 {

                 .
                 .

                 .
                 }



                          Way-3
                          Formal parameters as an unsized array:

                 void myFunction(int param[])

                 {

                 .
                 .
                 .

                 }



                          Example
                          Now, consider the following function, which takes an array as an argument along with
                   another argument and based on the passed arguments, it returns the average of the numbers passed
                   through the array as follows:


                 double getAverage(int arr[], int size)

                 {
                   int      i;

                   double avg;
                   double sum;



                   for (i = 0; i < size; ++i)

                   {
                      sum += arr[i];

                   }



                   avg = sum / size;
                                                                                                      95
   87   88   89   90   91   92   93   94   95   96   97