Printf它的变化和原型的理解

时间:2013-09-08 17:32:29

标签: 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原型? 这与动态链接有什么关系吗? 任何人都可以展示一些其他奇怪的printfs并解释它们。

1 个答案:

答案 0 :(得分:1)

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

当C编译器看到两个字符串之间没有任何字符串(除了可能的空格)之外,它将它们视为单个字符串。这样可以更容易地在多行中断开长字符串。 因此"hello""my""friend"编译成与"hellomyfriend"

完全相同的内容
"hello"
"my"
"friend"

这些都与printf无关,与字符串有很大关系。