在C/C++中,int、char、double、long所占的字节数

所占字节数和机器字长及编译器有关:
所以,intlong intshort int的宽度都可能随编译器而异。但有几条铁定的原则(ANSI/ISO制定的):

sizeof(short int) <= sizeof(int)
sizeof(int) <= sizeof(long int)
short int至少为16bit(2byte)
long int 至少应为32byte

16位编译器

char             1byte
char*            2byte
short int        2byte
int              2byte
unsigned int     2byte
float            4byte
double           8byte
long             4byte
long long        8byte
unsigned long    4byte

32位编译器

char             1byte
char*            4byte
short int        2byte
int              4byte
unsigned int     4byte
float            4byte
double           8byte
long             4byte
long long        8byte
unsigned long    4byte

64位编译器

char             1byte
char*            8byte
short int        2byte
int              4byte
unsigned int     4byte
float            4byte
double           8byte
long             8byte
long long        8byte
unsigned long    8byte

char*表示指针变量,它存的是变量的地址,所以在同一编译器下,不管是char*还是int*,它们所占位数都是相同的。
32位的寻址空间是2^32,即32bit,也就是4byte,所以32位编译器中char*(指针变量)占4byte。同理64位编译器占8byte

  • 0
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值