Arrays as Arguments - C++ Data Type

C++ examples for Data Type:Array

Description

Arrays as Arguments

Demo Code

#include <iostream>
using namespace std;
const int MAXELS = 5;
int findMax(int [MAXELS]);     // function prototype
int main()/*from   w w  w. j  a v a2 s .c o m*/
{
   int nums[MAXELS] = {2, 18, 1, 27, 16};
   cout << "The maximum value is " << findMax(nums) << endl;
   return 0;
}
// Find the maximum value
int findMax(int vals[MAXELS])
{
   int i, max = vals[0];
   for (i = 1; i < MAXELS; i++) {
      if (max < vals[i]) {
         max = vals[i];
      }
   }
   return max;
}

Result


Related Tutorials