任何人都可以解释printf语法的变化。我对其中的某些内容感到困惑 像
printf(5+"hello my friend");//i have problem this addition of 5
printf("hello""my""friend");//i have problem with double apostrophe
这是什么样的printf原型? 这与动态链接有什么关系吗? 任何人都可以展示一些其他奇怪的printfs并解释它们。
答案 0 :(得分:1)
通过指向char
的指针访问C中的字符串(有关更精确的定义,请参阅H2CO3的注释)。如果将5
添加到指向char
的指针,则稍后将启动字符串5个字符。因此5+"hello my friend"
指向" my friend"
,跳过"hello"
。
当C编译器看到两个字符串之间没有任何字符串(除了可能的空格)之外,它将它们视为单个字符串。这样可以更容易地在多行中断开长字符串。
因此"hello""my""friend"
编译成与"hellomyfriend"
或
"hello"
"my"
"friend"
这些都与printf
无关,与字符串有很大关系。