C语言中关于类型转换

最近在看视频学习中,学到了类型转换这一章节,故把学习笔记放上来。

1.小数据赋给大变量

不会造成数据的丢失,系统为了保证数据的完整性,还提供了符号扩充行为。这一点基本没什么好讲的,主要就是扩充了,数据不变。

但是关于有一部分转化需要讲。这里用到K&R的相关书写到的知识点如下:(中文版《C程序设计语言》)

(operand指的是操作数,就是 a+b 中的a和b)这里顺序从上至下

First,if either operand is long double , the other is converted to long double

•Otherwise , if either operand is double , the other is converted to double.

•Otherwise , if either operand is float , the other is converted to float.

•Otherwise,the integral promotions(整型提升) are performed on both operands 

•Otherwise,if either operand is unsigned int , the other is converted to unsigned int.

•Otherwise , both operands have type int.


2.大数据赋给小变量

会发生truncate(截断行为),有可能会造成数据丢失。具体看大数据的值在小变量里是否“放得下”。


版权声明:本文为博主原创文章,未经博主允许不得转载

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值