首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

char的范畴究竟是多少

2013-03-22 
char的范围究竟是多少。百度百科里面讲char是C/C++整型数据中比较古怪的一个,其它的如int/long/short等不指

char的范围究竟是多少。
百度百科里面讲
char是C/C++整型数据中比较古怪的一个,其它的如int/long/short等不指定signed/unsigned时都默认是signed,但char在标准中是unsigned,编译器可以实现为带符号的,也可以实现为不带符号的,有些编译器如pSOS的编译器,还可以通过编译开关来指定它是有符号数还是无符号数。

但是看过一本书说
char的范围是0-127
signed char的范围是-127到127
unsigned char的范围是0-255

char的范围不是应该是和unsigned char的范围一样都是0-127
[解决办法]


5.2.4.2.1
If the value of an object of type char is treated as a signed integer when used in an
expression, the value of CHAR_MIN shall be the same as that of SCHAR_MIN and the
value of CHAR_MAX shall be the same as that of SCHAR_MAX. Otherwise, the value of
CHAR_MIN shall be 0 and the value of CHAR_MAX shall be the same as that of
UCHAR_MAX.15) The value UCHAR_MAX shall equal 2^CHAR_BIT - 1.



J.3.4 Implementation-defined behavior:

Which of signed char or unsigned char has the same range, representation,
and behavior as ‘‘plain’’ char (6.2.5, 6.3.1.1).

热点排行