Compilation of string literals

后端 未结 5 1225
臣服心动
臣服心动 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:20

    If you see e.g. this translation phase reference in phase 6 it does:

    Adjacent string literals are concatenated.

    And that's exactly what happens here. You have two adjacent string literals, and they are concatenated into a single string literal.

    It is standard behavior.

    It only works for string literals, not two pointer variables, as you noticed.

提交回复
热议问题