并列的字符串被连接成新的字符串

并列字符串被连接成新的字符串

在分隔符“,”间的多个字符串

  • 分隔符间的多个字符串属于并列关系,在翻译阶段时,多个并列的字符串会被连接到一起,形成新的字符串;
  • c++标准文档引用:
String literals placed side-by-side are concatenated at translation phase 6 (after the preprocessor). 
That is, "Hello,"  " world!"  yields the (single) string "Hello, world!". 
If the two strings have the same encoding prefix (or neither has one), the resulting string will have the same encoding prefix (or no prefix). 
Phase 6

Adjacent string literals are concatenated. 
  • 范例:
[root@localhost c]# cat test_printf.c
#include <stdio.h>

static const char * const MAX[] = {
    "large_" "and_" "big",
    "great_" "and_" "huge"
};
int main()
{
    printf("Hello %s!" "We will %s!\n", "world", "better");
    printf("MAX[0] = %s\n", MAX[0]);
    printf("MAX[1] = %s\n", MAX[1]);
    return 0;
}
[root@localhost c]# ./test_printf.o 
Hello world!We will better!
MAX[0] = large_and_big
MAX[1] = great_and_huge
[root@localhost c]# 

相关链接

https://en.cppreference.com/w/cpp/language/translation_phases
https://en.cppreference.com/w/cpp/language/string_literal

注:

本文是对于c++标准文档的一个粗浅的理解,如有错漏,请各位朋友指正,谢谢

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值