c语言大数支持库,C语言中的大数(big integer)擢升

第一个程序char.c

unsigned char x = 2;

signed char z = 5;

if((x-z)<0)

printf("x-z<0\n");

else if((x-z)>0)

printf("x-z>0\n");

输出结果是 x-z<0

第二个程序int.c

unsigned int x = 2;

signed int z = 5;

if((x-z)<0)

printf("x-z<0\n");

else if((x-z)>0)

printf("x-z>0\n");

输出结果是x-z>0

一般来说,无符号数和有符号数混合运算时,会自动转换为无符号数,那为什么数据类型定义成char和int会有不同的结果呢?这是因为K&R C中关于整型提升(integral promotion)的定义为:

"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."

参考http://blog.csdn.net/lovekatherine/article/details/1565969

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值