I'm new to c++ and I have recently spent a couple of days reading about pointers.I realized that the 2 following codes give me different results although they seem identical.
the first code:
int a = 5;
int* ptr = &a;
cout << ptr;
cout << "\n" << ++ptr;
the second code:
int a = 5;
int* ptr = &a;
cout << ptr << "\n" << ++ptr;
here is the output of the first one:
0043F940
0043F944
the output of the second one:
003AFE20
003AFE20
the first one seems more logical to me since it first outputs the address of a
and then the address of the next integer location.But in the second one ptr
is apparently always pointing to a
.
Can someone explain this difference to me?
Thank you in advance.