I found unexpected output of following program.
Here pointer ptr
point to address of variable i
and i
hold the value 10
. It means the value of ptr
also 10
. Next ptr
increment once. It means now it hold value 11
. But in the following program ptr prints 12
.
#include <iostream>
using namespace std;
int main()
{
int i = 10;
int *ptr = &i;
int j = 2;
j += *ptr++;
cout<<"i : "<<i<<"\n";
cout<<"j : "<<j<<"\n";
cout<<"ptr : "<<*ptr<<"\n";
}
i : 10
j : 12
ptr : 12
So I don't understand why ptr
prints 12
instead of 11
?