C语言关于类型的提升和转换

一、类型的提升
   把char、unsigned char、short、unsigned short转换成int类型称为类型提升(promotion)。
1. 如果short的字节长度小于int的字节长度
   char转换成 int
   unsigned char转换成 int
   short转换成 int
   unsigned short转换成 int
2. 如果short的字节长度等于int的字节长度
   char转换成 int
   unsigned char转换成 int
   short转换成 int
   unsigned short转换成 unsigned int
二、类型的转换
    long double、double、float、unsigned long long、long long、unsigned long、long、unsigned int、int之间的转换称为类型转换
1. 如果int的字节长度小于long的字节长度
   类型等级由高到低依次为:long double、double、float、 unsigned long long、long long、unsigned long、long、unsigned int、int
2. 如果int的字节长度等于long的字节长度
   类型等级由高到低依次为:long double、double、float、unsigned long long、long long、unsigned long、unsigned int、long、int

3. 在任何涉及两种数据类型的操作中,它们之间等级较低的类型会被转换成等级较高的类型。

转自《http://blog.sina.com.cn/s/blog_98271e2701016qdz.html》

附:64位环境下各个类型的大小: 

  size_t:  8 bytes
  void *:  8 bytes
   char:  1 bytes
   short:  2 bytes
    int:  4 bytes

   long:  8 bytes
long long:  8 bytes
   float:  4 bytes
  double:  8 bytes
long double: 16 bytes

 ssize_t:  8 bytes

  off_t:  8bytes



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值