Accessing each array element with the increment operator on its pointer. - C++ Data Type

C++ examples for Data Type:Array Pointer

Description

Accessing each array element with the increment operator on its pointer.

Demo Code

#include <iostream>
using namespace std;
int main()//from  w  ww  .  j  ava  2 s  . c om
{
   const int NUMS = 5;
   int nums[NUMS] = {16, 54, 7, 43, -5};
   int i, total = 0, *nPt;
   nPt = nums;    // store address of nums[0] in nPt
   for (i = 0; i < NUMS; i++)
      total = total + *nPt++;
   cout << "The total of the array elements is " << total << endl;
   return 0;
}

Result


Related Tutorials