#include<stdio.h>
int main()
{
int i = 10;
int *p = &i;
printf("\n address of initialized pointer p: %u \n", p);
p = &(*p);
printf("\n modified address of initialized pointer p:%u value:%d valuez address: %d \n", p, *p, &(*p));
return 0;
}
the code outputs:-
address of initialized pointer p: 3221221820
modified address of initialized pointer p:3221221820 value:10 valuez address: -1073745476
Why is “&(*p)”, behaving differently when used in a assignment statement and in a printf statement ?
Update
Sorry, just format specifier mistake in printf ;).Thanks for the replies and pointing out.
You are using incorrect format specifier in printf. Using
%dfor printing addresses won’t work. Use%prather. [%ufor printing address isn’t correct either.]This works as per expectation.