gpt4 book ai didi

c - 如何确定将多字符char常量赋值给char变量的结果?

转载 作者:行者123 更新时间:2023-11-30 17:59:01 24 4
gpt4 key购买 nike

为什么 char 变量从“ab”赋值中得到“b”,而不是“a”?

char c = 'ab';

printf("c: %c\n", c);

打印:

c: b

最佳答案

根据标准,它是实现定义的。来自 6.4.4.4 字符常量:

An integer character constant has type int. The value of an integer character constant containing a single character that maps to a single-byte execution character is the numerical value of the representation of the mapped character interpreted as an integer. The value of an integer character constant containing more than one character (e.g., 'ab'), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined.

关于c - 如何确定将多字符char常量赋值给char变量的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11835764/

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