Correct format specifier to print pointer or address?

前端 未结 5 1686
自闭症患者
自闭症患者 2020-11-21 13:17

Which format specifier should I be using to print the address of a variable? I am confused between the below lot.

%u - unsigned integer

%x

5条回答
  •  渐次进展
    2020-11-21 14:00

    As an alternative to the other (very good) answers, you could cast to uintptr_t or intptr_t (from stdint.h/inttypes.h) and use the corresponding integer conversion specifiers. This would allow more flexibility in how the pointer is formatted, but strictly speaking an implementation is not required to provide these typedefs.

提交回复
热议问题