How are the specifiers %p
and %Fp
working in the following code?
void main()
{
int i=85;
printf("%p %Fp",i,i);
getch();
}
I am getting the o/p as 0000000000000055 0000000000000055
Difference between %p and %x in C/C++The %p is used to print the pointer value, and %x is used to print hexadecimal values. Though pointers can also be displayed using %u, or %x. If we want to print some value using %p and %x then we will not feel any major differences.
By using '%p' you print the address of the variable in question, "The void * pointer argument is printed in hexadecimal (as if by %#x or %#lx)."
%p expects the argument to be of type (void *) and prints out the address. Whereas %x converts an unsigned int to unsigned hexadecimal and prints out the result.
As you already explained %d is used for signed integers, while %u is for unsigned integers. %p is used to print pointer addresses. Originally Answered: What are the actual differences between %d, %u and %p format specifiers used in C to print the memory address of a variable?
If this is what you are asking, %p and %Fp print out a pointer, specifically the address to which the pointer refers, and since it is printing out a part of your computer's architecture, it does so in Hexadecimal.
In C, you can cast between a pointer and an int, since a pointer is just a 32-bit or 64-bit number (depending on machine architecture) referring to the aforementioned chunk of memory.
And of course, 55 in hex is 85 in decimal.
%p is for printing a pointer address.
85 in decimal is 55 in hexadecimal.
On your system pointers are 64bit, so the full hexidecimal representation is: 0000000000000055
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With