Wednesday, April 13, 2011

C++ pointer (step 2)

#include
using namespace std;

int main ()
{
  int age[5];
  int *p;
  int sum=0;

  p=age;
  for(int i=0;i<5;i++)
  {
    cout << "Enter the age of a student" << endl;
    cin >> *p;
    sum=sum+*p;
    p++;
  }
  p=age;
  cout << "The sum of the ages is : " << sum << endl;
  cout << "The age of the last student is : " << *(p + 4) << endl;
  return 0;
}

0 comments:

Sponsored By