当前位置:网站首页>[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
边栏推荐
- MySQL - full text index
- 划分数据1
- Web Security Foundation - file upload (file upload bypass)
- ECCV 2022 | Tsinghua proposes the first transformer to embed spectral sparsity
- Erlang学习02
- Chapter V Modification implementation (impl) class
- 脚手架内各文件配置说明、组件化开发步骤
- This usage, SystemVerilog syntax
- Erlang learning 02
- Adobe Substance 3D Designer 2021软件安装包下载及安装教程
猜你喜欢

zoj-Swordfish-2022-5-6

IEPE vibration sensor synchronous signal acquisition card /icp synchronous data network acquisition module

分布式事务处理方案大 PK!

图像处理:RGB565转RGB888

谷歌联合高校研发通用模型ProteoGAN,可设计生成具有新功能的蛋白质

Web Security Foundation - file upload (file upload bypass)

MySQL - 多列索引

CMS vulnerability recurrence - foreground arbitrary user password modification vulnerability

Sentinel 实现 pull 模式规则持久化

Sentinel three flow control effects
随机推荐
js函数调用下载文件链接
题解——Leetcode题库第283题
zoj1137+作业1--2022年5月28日
pom文件dependency中的 scope用法
The paper of gaojingjian center was selected into the ACL 2022 of the international summit to further expand the privacy computing capacity of Chang'an chain
Erlang learning 02
Basic SQL operations
[electronic device note 4] inductance parameters and type selection
NLP introduction + practice: Chapter 2: introduction to pytorch
图像处理:RGB565转RGB888
PC Museum (1) 1970 datapoint 2000
Machine learning quiz (11) verification code recognition test - deep learning experiment using QT and tensorflow2
火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
脚手架文件目录说明、文件暴露
How to build a node development environment efficiently
Mysql database JDBC programming
Domain Driven practice summary (basic theory summary and analysis + Architecture Analysis and code design + specific application design analysis V) [easy to understand]
Will not be rejected! Learn the distributed architecture notes sorted out by Alibaba Daniel in 35 days, with a salary increase of 20K
Binlog and iptables prevent nmap scanning, xtrabackup full + incremental backup, and the relationship between redlog and binlog
N-tree, page_ Size, database strict mode modification, and the difference between delete and drop in the database