0

%x

What is the problem in 1st and 2nd printf function getting errors #include <stdio.h> int main() { int j = 63; int *p = NULL; p = &j; printf("The address of j is %x\n", &j); printf("p contains address %x\n", p); printf("The value of j is %d\n", j); printf("p is pointing to the value %d\n", *p); }

16th Apr 2021, 3:59 PM
Surya L
Surya L - avatar
4 Respostas
0
Hey Surya Raj 1. What is %x , I don't understand? 2.is your question that you are getting some value for 1st and 2nd printf fn ,they are the memory address of that variable. I think this code help you 👇 #include <stdio.h> int main() { int j = 63; int *p=NULL; p = &j; printf("The address of j is %ld\n", &j); printf("p contains address %ld\n", p); printf("The value of j is %d\n", j); printf("p is pointing to the value %d\n", *p); return 0; }
16th Apr 2021, 5:18 PM
Giriraj Yalpalwar
Giriraj Yalpalwar - avatar
+ 2
Surya Raj , The correct format specifier for printing address is %p. Replace %x with %p.
16th Apr 2021, 6:07 PM
Hima
Hima - avatar
0
It is printing one type of garbage value because the value changes when you re-run it
16th Apr 2021, 4:32 PM
Atul [Inactive]
0
Ok
16th Apr 2021, 4:33 PM
Surya L
Surya L - avatar