Add a couple of cout lines to the code and then run the code under the debugger, after putting a breakpoint on the first line under
int main()
. Step through the code line-by-line in the debugger, examining the contents of the variables before and after each line of code is executed and it should become obvious what's going on.
<pre>int main()
{
int a[] = { 5, 7, 9, 11, 14 };
int *p = a + 2;
cout << *p << endl;
cout << ++*p++ << endl;
cout << *p << endl;
}
The debugger is a tool to debug YOU and your understanding of the code, not the code itself. You have to learn to use this tool or you're just going to be guessing at what you're code is really doing.
How a compiler and CPU interpret and execute the code can be vastly different from how you interpret and execute the code in your head.