用空格隔开两个字符串被自动连接起来 [英] two strings separated by blank being concatenated automatically
问题描述
我刚刚找到了它是由我的错字介绍非常有趣。在这里,很容易code脚本示例:
I just found something very interesting which was introduced by my typo. Here's a sample of very easy code script:
printf("A" "B");
其结果将是
$> AB
有人能解释这是如何发生的?
Can someone explain how this happens?
推荐答案
由于C标准的一部分,字符串是一个接一个地被连接起来:
As a part of the C standard, string literals that are next to one another are concatenated:
有关C(报价C99,C11,但在6.4.5p5类似的东西):
For C (quoting C99, but C11 has something similar in 6.4.5p5):
(C99,6.4.5p5)在翻译阶段6,多字节字符
由相邻字符的任何序列指定序列和
identically- prefixed字符串令牌连接成
单一的多字节字符序列。
(C99, 6.4.5p5) "In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed string literal tokens are concatenated into a single multibyte character sequence."
C ++也有类似的标准。
C++ has a similar standard.
这篇关于用空格隔开两个字符串被自动连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!