CC++基本数据类型 字节数

C\C++基本数据类型 字节数

1字节=8位

1k=1024字节=2^10

C语言类型数据所占字节数和机器字长及编译器有关系,int,long int,short int的宽度都可能随编译器而异。但有几条铁定的原则(ANSI/ISO制订的):

  1. sizeof(short int)<=sizeof(int)
  2. sizeof(int)<=sizeof(long int)
  3. short int至少应为16位(2Byte)
  4. long int至少应为32位。

类型32位编译器64位编译器
char1 Byte1 Byte
char *(指针变量4 Byte(32bit=4Byte)8 Byte
short int2 Byte2 Byte
int4 Byte4 Byte
unsigned int4 Byte4 Byte
float4 Byte4 Byte
double8 Byte8 Byte
long4 Byte8 Byte
long long8 Byte8 Byte
unsigned long4 Byte8 Byte

验证方式: printf("%d",sizeof(char))


确定各数据类型取值范围(头文件<limits.h>中含有):

(char)((unsigned char) ~0 >>1)为signed类型字符最大值。

-(char)((unsigned char) ~0 >>1)为signed类型字符最小值。

  1. ~0 //各个二进制位全部转换成1
  2. (unsigned char) ~0 //结果转换成unsigned char 类型
  3. (unsigned char) ~0 >>1 //右移一位清除符号位
  4. (char)((unsigned char) ~0 >>1) //得到signed类型最大值 ,替换char得到其他类型取值范围。
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值