第一次写博客,有点小激动,主要的目的是将正在学习的知识记录一下,方便随时复习,也给跟我一样正在学习C++的同学分享一下我的学习过程,博客中所用的知识都是我在网上或者书上查到的(其实我已经学过一段时间了,现在想复习记录一下,哈哈哈),出处当时没有记录,如果有侵权,请联系删除,如果有错误,也欢迎大家指正,谢谢,费话不多说,开始吧
C/C++ 在16bit & 32bit & 64bit编译器下各数据类型字节数
C/C++ 中不同目标平台下各数据类型长度是不同的,数据类型的实际长度由编译器在编译期间通过编译参数指定目标平台而确定的。
short int,int,long int 的字节数都是随编译器指定的目标平台而异,但是在ANSI/ISO指定:
- sizeof(short int) <= sizeof(int);
- sizeof(int) <= sizeof(long int);
- short int >= 16 bit (2 Byte);
- long int >= 32 bit (4 Byte).
16bit 编译器:
- char == 1 Byte;
- short int == 2 Byte;
- int == 2 Byte;
- unsigned int == 2 Byte;
- long == 4 Byte;
- unsigned long == 4 Byte;
- long long == 8 Byte;
- float == 4 Byte;
- double == 8 Byte.
32bit 编译器:
- char == 1 Byte;
- short int == 2 Byte;
- int == 4 Byte;
- unsigned int == 4 Byte;
- long == 4 Byte;
- unsigned long == 4 Byte;
- long long == 8 Byte;
- float == 4 Byte;
- double == 8 Byte.
64bit 编译器:
- char == 1 Byte;
- short int == 2 Byte;
- int == 4 Byte;
- unsigned int == 4 Byte;
- long == 4 Byte;
- unsigned long == 4 Byte;
- long long == 8 Byte;
- float == 4 Byte;
- double == 8 Byte.
指针变量所占字节
指针变量所占字节数是根据编译器的寻址空间决定宽度的:
- 16 bit编译器寻址空间为16 bit,所以指针变量宽度为2 Byte;
- 32 bit编译器寻址空间为32 bit,所以指针变量宽度为4 Byte;
- 64 bit编译器寻址空间为64 bit,所以指针变量宽度为8 Byte.