C/C++ 各数据类型占用字节数

第一次写博客,有点小激动,主要的目的是将正在学习的知识记录一下,方便随时复习,也给跟我一样正在学习C++的同学分享一下我的学习过程,博客中所用的知识都是我在网上或者书上查到的(其实我已经学过一段时间了,现在想复习记录一下,哈哈哈),出处当时没有记录,如果有侵权,请联系删除,如果有错误,也欢迎大家指正,谢谢,费话不多说,开始吧

C/C++ 在16bit & 32bit & 64bit编译器下各数据类型字节数

C/C++ 中不同目标平台下各数据类型长度是不同的,数据类型的实际长度由编译器在编译期间通过编译参数指定目标平台而确定的。
short int,int,long int 的字节数都是随编译器指定的目标平台而异,但是在ANSI/ISO指定:

  1. sizeof(short int) <= sizeof(int);
  2. sizeof(int) <= sizeof(long int);
  3. short int >= 16 bit (2 Byte);
  4. long int >= 32 bit (4 Byte).

16bit 编译器:

  1. char == 1 Byte;
  2. short int == 2 Byte;
  3. int == 2 Byte;
  4. unsigned int == 2 Byte;
  5. long == 4 Byte;
  6. unsigned long == 4 Byte;
  7. long long == 8 Byte;
  8. float == 4 Byte;
  9. double == 8 Byte.

32bit 编译器:

  1. ​char == 1 Byte;
  2. short int == 2 Byte;
  3. int == 4 Byte;
  4. unsigned int == 4 Byte;
  5. long == 4 Byte;
  6. unsigned long == 4 Byte;
  7. long long == 8 Byte;
  8. float == 4 Byte;
  9. double == 8 Byte.

64bit 编译器:

  1. char == 1 Byte;
  2. short int == 2 Byte;
  3. int == 4 Byte;
  4. unsigned int == 4 Byte;
  5. long == 4 Byte;
  6. unsigned long == 4 Byte;
  7. long long == 8 Byte;
  8. float == 4 Byte;
  9. double == 8 Byte.

指针变量所占字节

指针变量所占字节数是根据编译器的寻址空间决定宽度的:

  1. 16 bit编译器寻址空间为16 bit,所以指针变量宽度为2 Byte;
  2. 32 bit编译器寻址空间为32 bit,所以指针变量宽度为4 Byte;
  3. 64 bit编译器寻址空间为64 bit,所以指针变量宽度为8 Byte.
以上32bit & 64bit编译器均是在vs2017上测试所得

下一篇:C/C++中float & double类型数据在内存中的存储形式

发布了20 篇原创文章 · 获赞 3 · 访问量 503

猜你喜欢

转载自blog.csdn.net/xiao_ma_nong_last/article/details/100087602
今日推荐