怎样正确使用 sizeof 来计算汉字的长度

\u0026#39;是\u0026#39;是int类型,不是字符型(c中\u0026#39;c\u0026#39;也是int型,但c++不是)------ 上面是手机输入的,所以没法多说,下面开始补充 ------1. 对于\u0026#39;a\u0026#39;,在C中属于int类型,在C++中属于char类型2. 对于\u0026#39;ab\u0026#39;,在C中属于int类型,在C++中也属于int类型3. 对于\u0026#39;ab\u0026#39;,其值是『实现定义』的4. ‘是’就是属于(3)所示的情况关于『多重字符常量』,C99标准文档如是说:The value of an integer character constant containing more than one character (e.g.,\u0026#39;ab\u0026#39;), or containing a character or escape sequence that does not map to a single-byte execution character, is implementation-defined.
■网友
UTF-8中文被编码后通常都是3字节
sizeof("是")=4;//3+1 【怎样正确使用 sizeof 来计算汉字的长度】 sizeof(\u0026#39;是\u0026#39;)在clang下面是编译不过的。
$ clang test.cpp test.cpp:3:24: error: character too large for enclosing character literal type printf("%d",sizeof(\u0026#39;是\u0026#39;)) ;
■网友
这个也要看你编辑器设置的编码类型的


    推荐阅读