当前位置:网站首页>Chapter IV expression
Chapter IV expression
2022-06-12 13:52:00 【Doll noodles I】
List of articles
1. Left and right
To sum up briefly : When an object is used as an R-value , Using the value of the object ( Content ). When an object is used as an lvalue , It's the identity of the object ( Location in memory . Address )
Where an R-value is required, an l-value can be used instead , But the right value cannot be used as the left value
2. Order of evaluation
int i = 0;
cout << i++ << " " << i << endl; //0 1
cout << i << " " << i++ << endl; //1 0
cout << i << " " << ++i << endl; //1 1
cout << ++i << " " << i << endl; //1 1
3. remainder
// Symbols only look at the remainder
-3 % 2 = -1;
3 % -2 = 1;
// Floating point number can't take remainder , And the remainder cannot be 0
4. Operator priority
Logic is not ! > The arithmetic ( Add, subtract, multiply and divide ) > Relationship ( Greater than or equal to but not equal to ) > Logic and && > Logic or || > assignment =;
* Priority of dereference < Front and back ++;
* Priority of dereference < .;
cout << *it++;
First ++, After ++ Will return to the original it;
Dereference is to dereference the original it;
5. Right association law , Multiple variables are assigned at the same time
int a, b, c;
a = b = c = 0;
int i;double d;
i = d = 3.5; //3 3.5
d = i = 3.5; //3 3
6. Assignment loop optimization writing
// before
int i = get_value();
while(1 != 42)
{
...
i = get_value();
}
// Now?
int i;
while((i = get_value) != 42)
{
...
}
7. sizeof
Satisfy the right union law . The resulting value is a size_t type
sizeof *p; // Right association law , Operation is equivalent to sizeof(*p). And don't care p Value , So whatever you return is 4
Be careful :
- When a character array represents a string , Its
sizeofValue will ’/0’ Count it in .(strlenCan't calculate ’\0’, And the terminator is encountered ’\0’ stop it ) - When the array is a formal parameter , Its
sizeofThe value is equivalent to the... Of the pointersizeofvalue .
8. Transformation in type
bool -> char -> unsigned char -> short -> unsigned short -> int -> long -> float -> double
9. Cast
//type For the target data type ,expression A variable or expression of the original data type
cast-name<type>(expression);
cast-name = [static_cast | dynamic_cast | const_cast | reinterpret_cast];
1.static_cast
It's equivalent to the traditional C Coercion in language , Can be cast to any type except the following ,
Can't switch off expression Of const、volatile、 perhaps __unaligned attribute .
2.const_cast
const_cast, Used to modify the type of const or volatile attribute .
This operator is used to modify the const( The only one with this ability C+±style Transformation operators ) or volatile attribute . except const or volatile Beyond modification , new_type and expression Of the same type .
- Constant pointers are converted into non constant pointers , And still point to the original object ;
- Constant references are converted to non constant references , And still point to the original object ;
- const_cast It is generally used to modify the bottom pointer . Such as const char *p form .
const int g = 20;
//int *h = &g;
int *h = const_cast<int *>(&g);
*h = 52;
cout << g + 10; //30
cout << *h + 10; //62
3.reinterpret_cast( It is not recommended to use )
type It must be a pointer 、 quote 、 Arithmetic Type 、 Function pointer or member pointer .
It can convert a pointer to an integer , You can also convert an integer to a pointer ( First convert a pointer to an integer , Then convert the integer to the pointer of the original type , You can also get the original pointer value ).
边栏推荐
- Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
- xcode 调试openGLES
- Simple implementation of gpuimage chain texture
- Comparator summary
- Codeforces 1629 D. pecuriar movie preferences - simple thinking, palindrome strings
- Behind the unsealing of Shanghai, this group of developers "cloud gathering" built an AI anti epidemic robot
- Tinyxml Usage Summary
- [WUSTCTF2020]颜值成绩查询-1
- Install RPM package offline using yum
- Greed issues - Egypt scores
猜你喜欢

Display logs in the database through loganalyzer

Data type conversion and conditional control statements

Behind the unsealing of Shanghai, this group of developers "cloud gathering" built an AI anti epidemic robot

CSDN博客积分规则

Codeforces 1629 F2. Game on sum (hard version) - Yang Hui's triangle, violence, finding rules

聊聊MySQL的10大经典错误
![[WUSTCTF2020]颜值成绩查询-1](/img/90/e4c2882357e0a1c6a80f778887e3f5.png)
[WUSTCTF2020]颜值成绩查询-1

Go language functions as parameters of functions

上海解封背后,这群开发者“云聚会”造了个AI抗疫机器人

Implementing pytorch style deep learning framework similartorch with numpy
随机推荐
Codeforces 1637 C. Andrew and stones - simple thinking
2062: [example 1.3] movie tickets
Tree reconstruction (pre order + middle order or post order + middle order)
[advanced MySQL] evolution of MySQL index data structure (IV)
Is MySQL query limit 1000,10 as fast as limit 10? How to crack deep paging
[WUSTCTF2020]颜值成绩查询-1
[wustctf2020] selfie score query -1
Comparator summary
阿里云开发板HaaS510解析串口JSON数据并发送属性
播放器屏幕方向方案
m1 pod install pod lint 失败解决方案
Greed issues - Egypt scores
【SemiDrive源码分析】【X9芯片启动流程】26 - R5 SafetyOS 之 LK_INIT_LEVEL_TARGET 阶段代码流程分析(TP Drvier、Audio Server初始化)
Scyther工具形式化分析Woo-Lam协议
GPUImage链式纹理的简单实现
Convert the string to hexadecimal string and display it
[MySQL advanced] index classification and index optimization scheme (V)
static 和 extern 关键字详解
Alibaba cloud development board haas510 connects to the Internet of things platform -- Haas essay solicitation
Application of binary search -- finding the square root sqrt of a number