1.用sizeof()运算符查看各数据类型大小

注意以下内部定义的别名:

unsigned short = unit16_t

unsigned int = uint32_t 

unsigned long (long) = uint64_t

#include

#include

using namespace std;

int main() {

cout << "char : " << sizeof(char) << "字节" << endl;

cout << "unsigned char : " << sizeof(uint8_t) << "字节" << endl;

cout << "w_char : " << sizeof(wchar_t) << "字节" << endl;

cout << "char16_t : " << sizeof(char16_t) << "字节" << endl;

cout << "char32_t : " << sizeof(char32_t) << "字节" << endl;

cout << "short : " << sizeof(short) << "字节" << endl;

cout << "unsigned short : " << sizeof(uint16_t) << "字节" << endl;

cout << "int : " << sizeof(int) << "字节" << endl;

cout << "unsigned int : " << sizeof(uint32_t) << "字节" << endl;

cout << "long : " << sizeof(long) << "字节" << endl;

cout << "long long : " << sizeof(long long) << "字节" << endl;

cout << "unsigned long (long) : " << sizeof(uint64_t) << "字节" << endl;

cout << "float : " << sizeof(float) << "字节" << endl;

cout << "double : " << sizeof(double) << "字节" << endl;

cout << "long double : " << sizeof(long double) << "字节" << endl;

return 0;

}

2.分别在VS 和 Linux 环境下运行代码并对比结果

 3.总结:

常见数据类型大小对比表(单位:字节)

类型WindowsUbuntu18char11unsigned char11short22unsigned short22int 44unsigned int44long48long long88unsigned long (long)88float44double88long double816w_char24char16_t22char32_t44

此外,32位系统的指针大小为4个字节,64位系统的指针大小为8个字节。

做笔记使用,如果有错误还请指正!!多谢!!!如果觉得总结的不错可以三连一手,嘻嘻~~

好文链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: