当前位置:网站首页>Automatic conversion and cast
Automatic conversion and cast
2022-07-28 16:20:00 【Foam o0】
The types of variables can be converted to each other , Conversion is divided into automatic conversion and forced conversion .
Automatic conversion rules :
- 1、 If the type of computation involved is different , First convert to the same type , And then you do the math .
- 2、 The conversion proceeds in the direction of increasing data length , To ensure that the accuracy does not decrease . Such as int The type and long Type operation , The first int Quantity into long Type and then do the operation .
a、 If the number of bytes of the two types is different , Convert to a type with a high number of bytes
b、 If the number of bytes of the two types is the same , And a sign , An unsigned , Then convert it to Unsigned type
- 3、 All floating-point operations are performed with double precision , Even if it only includes float Expression of single precision operation , It also needs to be converted into double type , Do some more calculations .
- 4、char The type and short When type is involved in the operation , It must be converted to int type .
- 5、 In assignment operations , The data types of the quantities on both sides of the assignment number are different , Assignment number The type of the right quantity will be converted to the type of the left quantity .
If the data type length of the quantity on the right is longer than that on the left , Some data will be lost , This will reduce the accuracy :
int a=1; double b=2.5; a=b; cout << a; // Output is 2, Missing decimal part
int a = 1; double b = 2.1; cout << "a + b = " << a + b << endl; // Output is a + b = 3.1
Cast rules :
Casts are enforced through Type conversion operations To achieve .
Its general form is :( Type specifier )( expression ) Its function is to cast the operation result of an expression into the type represented by a type specifier .
int a = 1; double b = 2.1; cout << "a + b = " << a + (int)b << endl; // Output is a + b = 3
边栏推荐
- mysql 查看事件状态语句和修改办法
- Learning methods 123
- Note: the value is rounded up to ten, hundred, thousand, ten thousand
- 激光测距仪非接触式地表裂缝监测仪
- js 队列
- 两种特殊函数(箭头函数和方法)
- Application of optical rain gauge to rainfall detection
- Is MySQL query limit 1000,10 as fast as limit 10? If I want to page, what should I do?
- Remote serial port server (adapter) UART to 1-wire application
- 仅需三步 轻松实现远程办公
猜你喜欢

MicTR01 Tester 开发套件(振弦采集读数仪)使用说明

2021 Kent interview question 2

2021 Yahong pen test question 2

Zhengda cup hacker marathon data analysis competition

Connection and application of portable borehole inclinometer data acquisition instrument and inclinometer probe

IFD-x 微型红外成像仪(模块)的温度测量和成像精度

Detectron2 installation and testing

Advantages of optical rain gauge over tipping bucket rain gauge

Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module

视频号找到金钥匙,抖音模仿后来人
随机推荐
Thermistor PT100, NTC to 0-10v/4-20ma converter
太阳能路灯的根本结构及作业原理
Why do most people who learn programming go to Shenzhen and Beijing?
Redis series 4: sentinel (sentinel mode) with high availability
Temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
Application of optical rain gauge to rainfall detection
记:数字累加动画
头条文章_signature
Implementation of skip table
【Multisim仿真】LM339过零电路仿真
One channel encoder, two channels Di speed measurement, RS485 serial port connected to one channel do alarm module ibf151
How to measure the vibrating wire sensor by vibrating wire acquisition module?
Laser rangefinder non-contact surface crack monitor
2021 肯特面试题2
Zhaoqi scientific innovation and entrepreneurship competition platform, activity roadshow, investment and financing docking
Rust 入门指南(crate 管理)
李宏毅《机器学习》丨4. Deep Learning(深度学习)
软件问题修复跟踪系统实战开发教程(上篇)
Numpy ndarray learning < II > miscellaneous records
两种特殊函数(箭头函数和方法)