为什么数组可以包含字符串元素?

问题描述 投票:0回答:1

我不明白为什么下面的数组中包含双引号;这不是字符串类型吗?

const uint8_t u8x8_font_8x13_1x2_n[436] U8X8_FONT_SECTION("u8x8_font_8x13_1x2_n") = 
  " :\1\2\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
  "\0\0\0\0\0@P\340\340P@\0\0\0\1\0\0\1\0\0\0\0\0\300\0\0\0\0\0\1\1\7"
  "\1\1\0\0\0\0\0\0\0\0\0\0\0 \30\30\10\0\0\0\0\0\0\0\0\0\0\0\0\1\1\1"
  "\1\1\0\0\0\0\0\0\0\0\0\0\0\0\20\70\20\0\0\0\0\0\0\0\200@\60\0\30\4\2\1"
  "\0\0\0\0\0\300 \20\20 \300\0\0\7\10\20\20\10\7\0\0@ \360\0\0\0\0\0\20\20\37"
  "\20\20\0\0\0`\20\20\20\20\340\0\0\30\24\22\22\21\20\0\0\20\20\20\220P\60\0\0\10\20\21"
  "\21\21\16\0\0\0\200@ \360\0\0\0\7\4\4\4\37\4\0\0\360\20\220\220\220\20\0\0\11\21\20"
  "\20\20\17\0\0\300 \20\20\20\0\0\0\17\22\21\21\21\16\0\0\20\20\20\220P\60\0\0\0\30\6"
  "\1\0\0\0\0\340\20\20\20\20\340\0\0\16\21\21\21\21\16\0\0\340\20\20\20\220\340\0\0\0\21\21"
  "\21\10\7\0\0\0\200\300\200\0\0\0\0\0\20\71\20\0\0";

下面的例子代表了我常用的数组声明格式。

int arr[10]={1,2,3,4,5,6,7,8,9,10};
c translation declaration string-concatenation string-literals
1个回答
1
投票

来自 C 标准(5.1.1.2 翻译阶段)

1 翻译语法规则的优先级由下式指定: 以下阶段。

//...

  1. 相邻的字符串文字标记被连接起来

例如这个声明

char s[] = "Hello World!";

相当于

char s[] = "Hello " 
           "World!";

将一个大字符串文字拆分为几个相邻的字符串文字可以使代码更具可读性。

© www.soinside.com 2019 - 2024. All rights reserved.