当前位置:网站首页>C语言类型转换
C语言类型转换
2022-07-21 02:24:00 【飞Link】
一、自动转换
1. 赋值语句中的自动转换
// 无精度损失
float a = 100;
int b = a;
// 有精度损失
float a = 100.5;
int b = a;
2. 混合运算中的自动转换
short int a = 1;
int b = 1;
float c = 1.0;
double d = 1.1;
sizeof(a); // 2
sizeof(a+b); // 4
sizeof(a+b+c); // 4
sizeof(a+b+c+d); // 8
3. 短的向长的转换
short\char
<int
<unsigned int
<float\long
<double
二、强制转换
(类型名) 表达式
(float) a; // 将变量a转换为float类型
(int) (x+y); // 把表达式x+y的结果转换为int型
(float) 5; // 将数值5(默认为int类型)转换为float
注意:类型转换只体现在结果上,并不会改变转换变量的类型
边栏推荐
- what? Does the multi merchant system not adapt to app? This is coming!
- Control in canoe panel: switch/indicator
- If the recommendation effect is not satisfactory, it's better to try to learn the propeller chart
- 微软关闭基本身份验证,对企业与员工有什么影响?
- Golang collection: custom types and method sets
- How to extract the specified column from the database of multiple imputation as a new variable
- 生成二维码
- What impact will Microsoft's closure of basic authentication have on enterprises and employees?
- Transplantation engineering method of STM32 OLED display screen
- 工业4.0数字孪生下的应用案例
猜你喜欢
通用分页(分页代码的封装)
If the recommendation effect is not satisfactory, it's better to try to learn the propeller chart
The risk control data (model) is not bothered because of the processing skills in this flow process
OREPA:阿里提出训练也很快的重参数策略,内存减半,速度加倍 | CVPR 2022
Php-cgi Remote Code Execution Vulnerability (cve-2012-1823)
安防视频监控平台EasyCVR数据库字段无法更新,如何优化?
Technology Encyclopedia | cloud native
测试必知必会的Mock数据方法
通用分頁(分頁代碼的封裝)
ESB結合UMC雲平臺開發說明
随机推荐
How much has changed from new retail to community group purchase?
Zhongang Mining: four trends of fluorite industry development
有趣的 Kotlin 0x0D:IntArray vs Array<Int>
Okaleido tiger NFT即将登录Binance NFT平台,NFT权益时代即将开启
C language practice topic + answer: 26-30
数字孪生技术打造智慧矿山可视化解决方案
Interesting kotlin 0x0D: intarray vs array < int>
嵌入式学习:Cortex-M系列芯片介绍
2022 dsctf first digital space security attack and defense competition
Application cases and common technologies of digital twins
c语言入门---操作符
el-table支持分页多选
机器学习-单变量线性回归
Php-cgi Remote Code Execution Vulnerability (cve-2012-1823)
Digital twin technology offshore wind farm solution
After leaving a foreign company, I know what respect and compliance are
[04] through the power consumption wall, what aspects should we improve "performance"?
The risk control data (model) is not bothered because of the processing skills in this flow process
C language -- 24 Gobang
pytorch利用nn.unfold重新实现卷积操作