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

标签 c printf

任何人都可以解释 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/

相关文章:

用 libtasn1.h 编译 c

c - 下载的文件未保存在给定位置

c - 如何将 zenity -entry 的输出分配给 C 语言变量?

c - printf ("%.17g\n", .1) 应该打印什么?

Java PrintWriter 输出在记事本中看起来很奇怪

c - 为什么 printf 在调用后不会刷新,除非格式字符串中有换行符?

c - *(++ptr) 是什么样的运算符?

c - HiTech/Microchip C 的免费静态检查器?

bash - ANSI 转义在 `printf` 中不起作用

C++ 和 printf - 奇怪的字符输出