gpt4 book ai didi

c - 转义序列差异

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:00 24 4
gpt4 key购买 nike

 #include<stdio.h>
int main()
{
int i=0;
printf("%d:%4d\n",++i,'\1');
printf("%d:%4d\n",++i,'\2');
printf("%d:%4d\n",++i,'\3');
printf("%d:%4d\n",++i,'\4');
printf("%d:%4d\n",++i,'\5');
printf("%d:%4d\n",++i,'\6');
printf("%d:%4d\n",++i,'\7');
printf("%d:%4d\n",++i,'\8');
printf("%d:%4d\n",++i,'\9');
printf("%d:%4d\n",++i,'\10');
printf("%d:%4d\n",++i,'\11');
printf("%d:%4d\n",++i,'\12');
printf("%d:%4d\n",++i,'\13');
printf("%d:%4d\n",++i,'\14');
printf("%d:%4d\n",++i,'\15');
printf("%d:%4d\n",++i,'\16');
printf("%d:%4d\n",++i,'\17');
printf("%d:%4d\n",++i,'\18');
printf("%d:%4d\n",++i,'\19');
printf("%d:%4d\n",++i,'\20');
printf("%d:%4d\n",++i,'\21');
printf("%d:%4d\n",++i,'\22');
printf("%d:%4d\n",++i,'\23');
printf("%d:%4d\n",++i,'\24');
printf("%d:%4d\n",++i,'\25');
printf("%d:%4d\n",++i,'\26');
printf("%d:%4d\n",++i,'\27');
printf("%d:%4d\n",++i,'\28');
printf("%d:%4d\n",++i,'\29');
printf("%d:%4d\n",++i,'\30');
return 0;
}

输出:

1:   1
2: 2
3: 3
4: 4
5: 5
6: 6
7: 7
8: 56
9: 57
10: 8
11: 9
12: 10
13: 11
14: 12
15: 13
16: 14
17: 15
18: 312
19: 313
20: 16
21: 17
22: 18
23: 19
24: 20
25: 21
26: 22
27: 23
28: 568
29: 569
30: 24

'\1'不就相当于ASCII值为1的字符吗?
为什么在输出中,8、9、18、19、28、29...的数字顺序不对? http://codepad.org/I1N6A71j

最佳答案

从 2.14.3 开始:

The escape \ooo consists of the backslash followed by one, two, or three octal digits that are taken to specify the value of the desired character. The escape \xhhh consists of the backslash followed by x followed by one or more hexadecimal digits that are taken to specify the value of the desired character. There is no limit to the number of digits in a hexadecimal sequence. A sequence of octal or hexadecimal digits is terminated by the first character that is not an octal digit or a hexadecimal digit, respectively.

由于 \8\18 不是有效的八进制序列,这些文字的含义取决于您的平台:

Escape sequences in which the character following the backslash is not listed in Table 7 are conditionally-supported, with implementation-defined semantics.

关于c - 转义序列差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10471059/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com