sizeof('ab') 等于 C++ 中的 sizeof(int) 吗?

Is sizeof('ab') equal to sizeof(int) in C++?

考虑到我有以下确定多字节字符大小的程序。

#include<iostream>

int main()
{
   std::cout<<"size of multibyte characters : "<<sizeof('ab')<<std::endl;
}

我的 GCC 编译器给出了 4 的输出。

所以我有以下问题:

这是所谓的多字符文字,与对应的单字符文字不同,它不是 char 类型,而是 int 类型(假设支持)。如[lex.ccon]/2中所述,强调我的:

A character literal that does not begin with u8, u, U, or L is an ordinary character literal. An ordinary character literal that contains a single c-char representable in the execution character set has type char, with value equal to the numerical value of the encoding of the c-char in the execution character set. An ordinary character literal that contains more than one c-char is a multicharacter literal. A multicharacter literal, or an ordinary character literal containing a single c-char not representable in the execution character set, is conditionally-supported, has type int, and has an implementation-defined value.

所以你打印 sizeof(int),如你所料。