Hi,
Can someone explain to me what is going on in the code below as im new to pointers and not quite sure what is going on..In particular, an explanation of the first couple of iterations in the for loops would be helpfull..
Thanks
#include<iostream>
5 using namespace std;
6
7 int main()
8 {
9 int x[5] = {1,2,3,4,5};
10 int *q, *p = &x[0];
11
12 //increment all values in the array by 1
13 q = p;
14 for (int i=0; i<5; i++)
15 {
16 (*q++)++;
17 }
18
19 //reset q pointer again
20 q = p;
21 for (int i=0; i<5; i++)
22 {
23 (*(q+i))++;
24 }