I have a question about increasing pointers, which I don't quite understand.
Allows you to see two small programs:
int iTuna=1; int* pPointer= &iTuna; *pPointer = *pPointer + 1 ;
In this first program, I increment what pPointer points to this "* pPointer = * pPointer +1". And since I expected iTuna to change to "2" and the program will print the value "2"
int iTuna=1; int* pPointer= &iTuna; *pPointer++; //Increment what pPointer is pointing to. cout << iTuna << endl; system("PAUSE"); return 0;
Here I incremented the increment pointed to by pPointer, this is "* pPointer ++". But here iTuna remains “1” and the programs print out the value “1”. Although I expected this to work first, it is not.
Please help me and tell me why the second piece of code does not work, as I expected, and how to get around it.
thanks
source share