C语言字符串空格分隔

char str[]="hello" "World";
这个是什么语法,没有看到过。哪里有讲解吗?

阅读 7.6k
2 个回答

"hello" "World" => "helloWorld"

c语言会忽略多个定义字符串之间的空白字符,把这些字符串拼接为一个字符串。


en.cppreference.com/w/c/language/string_literal

First, at translation phase 6 (after macro expansion), the adjacent string literals (that is, string literals separated by whitespace only) are concatenated.

char* p = "\x12" "3"; // creates a static char[3] array holding {'\x12', '3', '\0'} 
                      // sets p to point to the first element of the array

//char* p = "\xfff"; // error: hex escape sequence out of range
char* p = "\xff""f"; // okay, the literal is char[3] holding {'\xff', 'f', '\0'}

ANSIC中引入的新特性,上一个书上例子,《C专家编程》中的例子。

图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进