C 为什么我会错过“结束”这个角色?
在示例1中,编译器没有显示任何错误,但在示例2中,它显示了一个缺少终止字符的错误。为什么?C字符串文本不能包含文本换行符。下面是标准,突出显示了相关部分 6.4.5字符串文字 语法C 为什么我会错过“结束”这个角色?,c,linux,gcc,compiler-errors,C,Linux,Gcc,Compiler Errors,在示例1中,编译器没有显示任何错误,但在示例2中,它显示了一个缺少终止字符的错误。为什么?C字符串文本不能包含文本换行符。下面是标准,突出显示了相关部分 6.4.5字符串文字 语法 //example1 #include<stdio.h> int main() { printf("hello World" ); } //example2 #include<stdio.h> int main() { printf("hello World ");
//example1
#include<stdio.h>
int main()
{
printf("hello World"
);
}
//example2
#include<stdio.h>
int main()
{
printf("hello World
");
}
在exapmle2中,编译器无法定位同一行中的结尾,而在example1中则无法定位。您可能希望使用like printfhello World second line;先生,在您的示例中,如果在第一行中未找到分号,编译器将如何处理语句?您可以在标记之间的任何位置使用换行符,而不是在字符串文本中。编译器将继续读取行,直到找到;。
string-literal:
encoding-prefixopt " s-char-sequenceopt "
s-char-sequence:
s-char
s-char-sequence s-char
s-char:
any member of the source character set except
the double-quote ", backslash \, or new-line character <---- HERE
escape-sequence
printf("hello "
"world");