Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
397 views
in Technique[技术] by (71.8m points)

%p Format specifier in c

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...