In my cout statement:
cout << ia[cnt++] << "\t" << *beg << "\t" << beg++ << endl;
beg++
affects the output of the earlier *beg
statement, and I can't understand why?
Full code:
int ia[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int *beg = begin(ia); // pointer to the first element in ia
int *last = end(ia); // pointer one past the last element in ia
int cnt = 0;
while (beg != last)
{
cout << ia[cnt++] << "\t" << *beg << "\t" << beg++ << endl;
}
Moving the incrementation of beg
to after the cout statement causes the code to function as I would expect. Can anyone please explain what's happening here?