📜  C / C++中的行拼接

📅  最后修改于: 2021-05-26 01:56:18             🧑  作者: Mango

在编写程序时,有时我们会在单/双注释行的帮助下在注释部分中提供有关代码工作的注释。但是我们从未想到过,如果在此注释行的末尾使用\(反斜杠)字符,那么会发生什么?
上述问题的答案是行拼接。在翻译过程中,很早就将以\终止的行与下一行拼接在一起。 §2.2翻译阶段。
实际上,每当在注释行的末尾使用\(反斜杠)字符,它将合并下一行与当前行,这使得新行也作为编译器的注释。为避免此问题,可以使用多行注释。

C
// C program to illustrate the concept of Line splicing.
#include 
int main()
{
    // Line Splicing\
    printf("Hello GFG\n");
    printf("welcome\n");
    /* Example 2 - both of the below lines will be printed*/ \
    printf("Hello\t");
    printf("World");
    return (0);
}


输出:

欢迎

你好,世界

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。