What is the behavior of the conversion specifier `p` with `NULL` pointer?

后端 未结 2 500
南旧
南旧 2021-01-17 11:52

I wonder if does:

void *ptr = NULL;
printf(\"%p\\n\", ptr);

Will always gives (nil) output?

Does it depend on standard

2条回答
  •  太阳男子
    2021-01-17 12:16

    On my system it yields (null) so I guess it's implementation defined. More generally, everything %p prints is implementation-defined:

    7.21.6.1

    The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner.

提交回复
热议问题