当前位置:网站首页>[dish of learning notes dog learning C] evaluation expression
[dish of learning notes dog learning C] evaluation expression
2022-07-24 10:35:00 【Jiang Junzhu】
List of articles
Expression evaluation
The order in which expressions are evaluated is partly determined by the operators priority and associativity decision . The operands of some expressions may need to be converted to other types in the evaluation process .
Implicit type conversion
Improve the overall shape
significance : The integer operation of the expression is in CPU Executed in the corresponding computing device of ,CPU Inner integer arithmetic unit (ALU) The byte length of the operands of It's usually int Byte length of , It's also CPU The length of a general-purpose register . therefore , Even two char Type addition , stay CPU When executing, it should be converted to CPU The standard length of the inner operands . Universal CPU It is difficult to realize two directly 8 Bits and bytes are directly added ( Although there may be such byte addition instructions in machine instructions ). So all kinds of expressions The length is less than int The integer value of the length , Must be converted to int perhaps unsigned int, Then it can be sent in CPU To perform the operation .
How to improve : according to Sign bit of variable data type To improve .
int main() {
char a = 3;
//00000011
char b = 127;
//01111111
char c = a + b;
// Improve the overall shape
//a - 00000000 00000000 00000000 00000011
//b - 00000000 00000000 00000000 01111111
//c - 00000000 00000000 00000000 10000010
//char Type only 8 A bit ,c To truncate
//c - 10000010
printf("%d", c);
//%d What is printed is an integer , therefore c To do integer lifting
// Integer promotion is promoted according to the sign bit of the data type of the variable
//10000010 The sign bit of is 1, So make up 1
//11111111 11111111 11111111 10000010 - Complement code
//11111111 11111111 11111111 10000001 - Inverse code
//10000000 00000000 00000000 01111110 - -126 - Original code
return 0;
}
Arithmetic conversion
If the operands of an operator belong to different types , Then unless one of the operands is converted to the type of the other operand , Otherwise, the operation cannot be carried out .
If the type of an operand is low in the list , Then first convert to the type of another operand and perform the operation .
long double
double
float
unsigned long int
long int
unsigned int
int
Arithmetic conversions are To types with higher accuracy convert .
Arithmetic conversion must be reasonable , Otherwise there will be problems , If accuracy is lost .
int main() {
int a = 4;
float f = 4.5f;
a + f;
//a Will send to float transformation
return 0;
}
Operator properties
There are three factors that affect the evaluation of complex expressions :
1. The priority of the operator
2. The associativity of operators
3. Whether to control the order of evaluation
int main() {
int a = 1;
int b = 2;
int c = a + b * 7;// Priority determines the order of calculation
int d = a + b + 7;// Priority does not work , Associativity determines order
return 0;
}
The priority and associativity of operators are to make the code run more logically and accurately , Not for people to show off their skills , Write a bunch of operators to show how well you master priority and associativity ;
If an expression cannot determine the unique calculation path through the attributes of the operator , Then this expression is problematic .
attach :C List of priorities and associativity of language operators
边栏推荐
- Partition data 1
- WEB安全基础 - - -文件上传(文件上传绕过)
- Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire
- [correcting Hongming] what? I forgot to take the "math required course"!
- PC博物馆(2) 1972年 HP-9830A
- 图像处理:浮点数转定点数
- PyTorch 常用 Tricks 总结
- MySQL - 索引的隐藏和删除
- Erlang学习02
- 协议圣经-谈端口和四元组
猜你喜欢
随机推荐
[leecode] get the longest common substring of two strings
Adobe Substance 3D Designer 2021软件安装包下载及安装教程
Kotlin domain specific language (DSL)
N叉树、page_size、数据库严格模式修改、数据库中delect和drop的不同
binlog、iptables防止nmap扫描、xtrabackup全量+增量备份以及redlog和binlog两者的关系
New:Bryntum Grid 5.1.0 Crack
机器学习小试(10)使用Qt与Tensorflow创建CNN/FNN测试环境
JS function call download file link
Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions
binlog、iptables防止nmap扫描、xtrabackup全量+增量备份以及redlog和binlog两者的关系
图像处理:浮点数转定点数
ffmpeg花屏解决(修改源码,丢弃不完整帧)
Activity exception lifecycle
The method modified by private can be accessed through reflection. What is the meaning of private?
Binlog and iptables prevent nmap scanning, xtrabackup full + incremental backup, and the relationship between redlog and binlog
PC博物馆(2) 1972年 HP-9830A
How to build a node development environment efficiently
NIO知识点
zoj1137+作业1--2022年5月28日
Daily three questions 7.21







