C++ Array Pointer adding array elements til address in array pointer is less than or equal to the address of the last array element

Description

C++ Array Pointer adding array elements til address in array pointer is less than or equal to the address of the last array element

#include <iostream>
using namespace std;
int main()/*from   w  ww . ja va2  s .c  om*/
{
   const int NUMS = 5;
   int nums[NUMS] = {1, 4, 7, 3, -5};
   int total = 0, *nPt;
   nPt = nums;    // store address of nums[0] in nPt
   while (nPt < nums + NUMS)
      total += *nPt++;
   cout << "The total of the array elements is " << total << endl;
   return 0;
}



PreviousNext

Related