Compilation of string literals

后端 未结 5 1226
臣服心动
臣服心动 2021-01-13 16:32

Why can two string literals separated by a space, tab or \"\\n\" be compiled without an error?

int main()
{
   char * a = \"aaaa\"  \"bbbb\";
} 
5条回答
  •  悲哀的现实
    2021-01-13 17:13

    In this statement

    char * a = "aaaa"  "bbbb";
    

    the compiler in some step of compilation before the syntax analysis considers adjacent string literals as one literal.

    So for the compiler the above statement is equivalent to

    char * a = "aaaabbbb";
    

    that is the compiler stores only one string literal "aaaabbbb"

提交回复
热议问题