#include <stdio.h>
int main(){
int i=1;
int * p = &i;
*(p++)=4;
printf("%p\n", p); //0x7ffc000f47c8
printf("%u\n", p); //956816552 (which is 0x7ffc000f47c8 as unsigned integer)
printf("%u\n", *p); //956816552 (I would expect *p to be the value of whatever is in 0x7ffc000f47c8, and not the unsigned value of the pointer p (956816552))
return 0;
}
I would expect the printf()
of *p
to be the value of whatever is in 0x7ffc000f47c8, and not the unsigned value of the pointer p
(956816552))
When/How did I set the value of *p
to 956816552 (value of p
)??
I believe *p++ = 4
isn't UB.
(According to the comments of the 1st answer - Undefined behavior and sequence points)
Any help will be much appreciated. Thanks.