int calculate (int member[], int size)

{

   int i, average = 0;



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

      average += member [i];



   average /= size;

   return average;

}



int main ( )

{

   int average, student [5] = {67, 93, 88, 89, 74};

   average = calculate (student, 5);

   cout << "The average score is " << average << endl;

   cin >> average;

   return 0;

}

To indicate to the compiler that a function is expecting an array, there must be “[ ]” following the array name in both the function prototype and function definition.

C++ automatically passes arrays by reference. Dereferencing operator “&” is not used, because the name of the array is the address of the first array element - the name of array "student" is equal to "&student[0]". 

Posted By :-Cplusplusprogramming
Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates