我认为标题是不言自明的,但更好的格式。
sizeof(unsigned char)
也保证是1吗?
我不相信这个问题是重复的,因为:
...It was originally designed as an extension to C, and keeps a similar syntax, but is now a completely different language...
)不同。char
可以是已签名或未签名。没有理由假设sizeof(unsigned char)
== sizeof(char)
,除非你得到标准的保证,因此问题。答案 0 :(得分:8)
参考:http://en.cppreference.com/w/cpp/language/sizeof
sizeof(char),sizeof(signed char)和sizeof(unsigned char)总是如此 返回1.
答案 1 :(得分:6)
是
[expr.sizeof] / 1:
sizeof(char)
,sizeof(signed char)
和sizeof(unsigned char)
为1
。
另外,[basic.fundamental] / 1:
char
,signed char
和unsigned char
占用相同数量的存储空间并具有相同的对齐要求