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字节。