【C语言】整形提升和整形截断

整形提升:K&R(C语言第一本编程书的编著者)在C中将整形提升定义为:“A character, a short integer, or an integer bit-field, all either signed or not, or an object of enumeration type, may be used in an expression wherever an in...
摘要由CSDN通过智能技术生成

整形提升:

K&R(C语言第一本编程书的编著者)在C中将整形提升定义为:
“A character, a short integer, or an integer bit-field, all either signed or not, or an object of enumeration type, may be used in an expression wherever an integer maybe used. If an int can represent all the values of the original type, then the value is converted to int; otherwise the value is converted to unsigned int. This process is called integral promotion.”
大致意思分为两点:

  • 1.只要一个表达式中用到了整形,那么类型为char, short int或整形位域的变量,以及枚举的类型都可以被放在这个整形变量的位置。
  • 2.如果条件一中的原始类型值域可以被int表示,那么原值转换为int,否则的话,转换unsigned。

以上两点的结合,被称为整形提升

举例说明:
  • 1.关于条件1的举证:
#include<iostream>

using namespace std;

int main()
{
   
	unsigned char a = 100;
	unsigned char b = 200;
	unsigned 
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值