我知道 C 和 C++ 是不同的语言。
代码 - C
#include <stdio.h>
int main()
{
printf("%zu",sizeof('a'));
return 0;
}
输出
4
代码 - C++
#include <iostream>
int main()
{
std::cout<<sizeof('a');
return 0;
}
输出
1
https://stackoverflow.com/a/14822074/11862989在这个答案中用户Kerrek SB(438k Rep.)
讲述 C++ 中的类型也没有提及 char
两者都不是int
但只是不可或缺的。
C++中的char是整型还是严格char类型?
最佳答案
is char in C++ is integral type or strict char type ?
字符类型,例如 char
,是 C++ 中的整型。
C 中窄字符常量的类型为 int
,而 C++ 中窄字符常量的类型为 char
。
关于c++ - C 和 C++ 中 char 的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70031324/