最近在看视频学习中,学到了类型转换这一章节,故把学习笔记放上来。
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(截断行为),有可能会造成数据丢失。具体看大数据的值在小变量里是否“放得下”。
版权声明:本文为博主原创文章,未经博主允许不得转载