字符的大小

来源:互联网 发布:java异常关键字怎么用 编辑:程序博客网 时间:2024/05/19 17:50

C标准ISO/IEC 9899:TC3是这样说的:
An integer character constant has type int

 

C++标准ISO/IEC 14882:2003(E)是这样说的:
An ordinary character literal that contains a single c-char has type
char

所以对sizeof('A')这种字符常量的大小,在C语言中输出4,gcc的结果确实是4.而且char a='abcd'这种也是正确的,因为这个正好是4个字节,如果char a='abcde'就报错了。这里最终a会等于最右边的。

 

C++中sizeof('A')占1个字节,但sizeof('abc')和C中是一样的都是4字节。

原创粉丝点击