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.
Answer checked How we write and check questions
Discussion