gpt4 book ai didi

c - 为什么 printf(char[]) 会生成警告,同时 printf ("asdf") 不会

转载 作者:太空狗 更新时间:2023-10-29 14:53:29 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
warning: format not a string literal and no format arguments

我有一个非常简单的问题:为什么当我制作 char[] s = "hi"; printf(s) 它会发出警告:“警告:格式不是字符串文字且没有格式参数”,同时 printf("aa") 不会。

我已经读过 char 数组和字符串文字之间的区别(一个是 const char const* 另一个是 char*),但是来自 printf () 签名:

http://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html#Formatted-Output-Functions

我发现它适合任何类型。所以我的问题是为什么 printf("aaa") 不发出任何警告(它是否以某种方式检查文字是否为 const,同时数组不是)?

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