Wednesday, April 13, 2011

C++ pointer (step 3)

#include
using namespace std;

int arrayInputSum(int *pa, int size)
{
  int *pp = pa;
  int sum = 0;
  for(int i=0;i
  {
    cout << "Enter the age of a student" << endl;
    cin >> *pp;
    sum=sum+*pp;
    pp++;
  }
  return sum;
}

int main ()
{
  int age[5];

  int sum = arrayInputSum(age,5);
  cout << "The sum of the ages is : " << sum << endl;

  return 0;
}

0 comments:

Sponsored By