How do you print an address?

The safest way is to use printf() (or fprintf() or sprintf()) with the %P specification. That prints a void pointer (void*). Different compilers might print a pointer with different formats. Your compiler will pick a format that’s right for your environment. If you have some other kind of pointer (not a void*) and you want to be very safe, cast the pointer to a void*: printf( “%Pn”, (void*) buffer );  

Showing Answers 1 - 2 of 2 Answers

ravisankar2

  • Feb 19th, 2006
 

THIS IS FROM c.ravi sankar reddy,hai to ALL........we can print the address of a variable or a function using the following specifiers %u,%p here %u prints address in decimal form and %p prints in hexa decimal form,but remember these two format specifiers print only offset adress but they doesn't print code segment address 

there is a another specifier %Fp which prints both the code segment and offset address

paulson paul chambakottukudyil

  • Apr 24th, 2006
 

I tried both %p and %Fp. There is no difference, atleast in MS visual studio. Both are printing the same value.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions