Pointers as Function Arguments : Function Pointer « Function « C++






Pointers as Function Arguments

Pointers as Function Arguments
 


#include <iostream>
using namespace std;
void assignValues(int[], int);
void displayValues(int[], int);
const int MAX = 3;

int main ()
{
   int testScore[MAX];
   assignValues(testScore, MAX);
   displayValues(testScore, MAX);  
   return 0;
}

void assignValues(int tests[], int num)
{
   for (int i = 0; i < num; i++)
   {
      cout << "Enter test score #" << i + 1 << ": ";
      cin >> tests[i];
   }
}

void displayValues(int scores[], int elems)
{
 for (int i = 0; i < elems; i++)
   {
      cout << "Test score #" << i + 1 << ": "
         << scores[i] << endl;
   }
}

           
         
  








Related examples in the same category

1.Assigning function pointers to overloaded functionsAssigning function pointers to overloaded functions
2.Pointer for empty string