如何两个字符串文字的串联工作? [英] How does concatenation of two string literals work?

查看:180
本文介绍了如何两个字符串文字的串联工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char* a="dsa" "qwe";
printf("%s",a);

输出:dsaqwe

output: dsaqwe

我的问题是,为什么做这件事的工作。如果我给在两者之间字符串的空间或没有它地连接了字符串。​​

My question is why does this thing work. If I give a space or nothing in between two string literals it concatenates the string literals.

这是如何工作?

推荐答案

它是由ISO C标准定义的,相邻的字符串组合成一个。

It's defined by the ISO C standard, adjacent string literals are combined into a single one.

语言是有点干燥(这是一个标准的毕竟),但部分 6.4.5字符串字面 C11的规定:

The language is a little dry (it is a standard after all) but section 6.4.5 String literals of C11 states:

在翻译阶段6,由任何序列指定的多字节字符序列
  相邻的性格和identically- prefixed宽字符串文字令牌连接成
  一个多字节字符序列。

In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed wide string literal tokens are concatenated into a single multibyte character sequence.

这也是在提到5.1.1.2转换阶段,6点,多了几分简洁:

This is also mentioned in 5.1.1.2 Translation phases, point 6, a little more succinctly:

相邻字符串文字令牌连接起来。

Adjacent string literal tokens are concatenated.

这基本上意味着ABC,高清是没有区别ABCDEF

This basically means that "abc" "def" is no different to "abcdef".

这是通常用于制作长字符串同时还具有不错的格式化有用:

It's often useful for making long strings while still having nice formatting:

char *myString = "This is a really long "
                 "string and I don't want "
                 "to make my lines in the "
                 "editor too long, because "
                 "I'm basically anal retentive :-)";

这篇关于如何两个字符串文字的串联工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆