The following piece of code, similar to your program:
#include <stdio.h>
int main()
{
int a=1,*p;
p=&a;
printf("p = %p, a = %d \n", p, a);
a=(*p)++;
printf("then\np = %p, a = %d \n", p, a);
return 0;
}
produces on my system:
p = 0x7ffe47db05bc, a = 1
then
p = 0x7ffe47db05bc, a = 1
(No changes)
While this one
#include <stdio.h>
int main()
{
int a=1,*p;
p=&a;
printf("p = %p, a = %d \n", p, a);
a=*p++; printf("then\np = %p, a = %d \n", p, a);
return 0;
}
produces
p = 0x7fff71b6233c, a = 1
then
p = 0x7fff71b62340, a = 1
(the value of
p
changed)
Finally, this one
#include <stdio.h>
int main()
{
int a=1,*p;
p=&a;
printf("p = %p, a = %d \n", p, a);
a=++(*p);
printf("then\np = %p, a = %d \n", p, a);
return 0;
}
produces
p = 0x7ffee94b2e2c, a = 1
then
p = 0x7ffee94b2e2c, a = 2
(the value of
a
changed)