gpt4 book ai didi

c - Printf 的变体及其原型(prototype)理解

转载 作者:行者123 更新时间:2023-11-30 19:22:03 26 4
gpt4 key购买 nike

任何人都可以解释 printf 语法的变化吗?我对其中的一些感到困惑喜欢

 printf(5+"hello my friend");//i have problem this addition of 5 
printf("hello""my""friend");//i have problem with double apostrophe

这些遵循什么样的 printf 原型(prototype)?这与动态链接有什么关系吗?谁能展示一些其他奇怪的 printfs 并解释它们。

最佳答案

C 中的字符串是通过指向 char 的指针来访问的(有关更精确的定义,请参阅 H2CO3 的注释)。如果将 5 添加到指向 char 的指针,则字符串将在 5 个字符后开始。因此 5+"hello myfriend" 指向 "myfriend",跳过 "hello"

当 C 编译器看到两个字符串之间没有任何内容(可能除了空格之外)时,它会将它们视为单个字符串。这使得将长字符串分成多行变得更容易。因此 "hello""my""friend" 编译成与 "hellomyfriend"

完全相同的东西
"hello"
"my"
"friend"

这些都与 printf 没有任何关系,而与字符串有很大关系。

关于c - Printf 的变体及其原型(prototype)理解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18686618/

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