Practice mode C Language

Which format specifier prints a pointer value with printf()?

Correct answer A. %p

Explanation

%p prints a pointer in an implementation-defined form, usually hexadecimal, and the argument should be converted to void *, as in printf("%p", (void *)ptr). Using %d or %x for a pointer is undefined behaviour because pointers are often 64 bits while int is 32 bits, so the wrong number of bytes would be read from the argument list.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.