c - 转换说明符 `p` 与 `NULL` 指针的行为是什么?

标签 c null printf

我想知道是否:

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

总是会给出 (nil) 输出吗?

它是依赖于标准库实现,还是 C99 标准规范?

最佳答案

在我的系统上它产生 (null) 所以我猜它是实现定义的。更一般地说,%p 打印的所有内容都是实现定义的:

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.

关于c - 转换说明符 `p` 与 `NULL` 指针的行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10461360/

相关文章:

c++ - 与执行随机快速排序相关的运行时错误

sql-server - SQL Server - 选择一行不会返回任何 NULL 值。为什么?

c++ - 在什么时候取消引用空指针会变成未定义的行为?

c - 只打印 double 的小数位

c++ - Linux 中的 sprintf uint64_t

C: 使用 printf 时出现段错误

c - 具有函数指针和 void 指针成员的结构的内存分配错误

c - 将整数读取为字符并将其打印为整数

c - 在 C 程序中使用 .txt 接收输入

excel - 在 Excel 中输出 NULL 单元格值