gpt4 book ai didi

c - 为什么代码片段 printf 的输出是 ("%. %. %. ");变成%.0 %.0 %.0?

转载 作者:行者123 更新时间:2023-11-30 20:49:48 25 4
gpt4 key购买 nike

我知道句点.符号精确地分隔字段宽度。但是,我不明白 % 之后的零是如何出现的。每次我运行时,它都会显示相同的输出。

代码:

#include <stdio.h>
int main() { printf("%. %. %. "); return 0; }

输出: %.0 %.0 %.0

main.c:13:15: warning: unknown conversion type character 0x20 in format [-Wformat=]                                                                                                         
main.c:13:18: warning: unknown conversion type character 0x20 in format [-Wformat=]
main.c:13:21: warning: unknown conversion type character 0x20 in format [-Wformat=]

最佳答案

您没有在 % 之后提供有效的转换说明符(例如 dxfgcsp 等),因此您正在调用 undefined behavior 。这意味着任何事情都可能发生。

摘自 ISO C99 标准第 7.19.6.1/9 节:

If a conversion specification is invalid, the behavior is undefined.239) If any argument is not the correct type for the corresponding conversion specification, the behavior is undefined.

关于c - 为什么代码片段 printf 的输出是 ("%. %. %. ");变成%.0 %.0 %.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58014082/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com