%p Format specifier in c

poorvank picture poorvank · Sep 28, 2012 · Viewed 94.4k times · Source

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

Answer

David Christo picture David Christo · Sep 28, 2012

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.