当前位置:网站首页>[C language - zero basis _ study _ review _ lesson 5] operational properties of basic operators
[C language - zero basis _ study _ review _ lesson 5] operational properties of basic operators
2022-07-27 09:15:00 【Super Daxiong】
The operational properties of basic operators
Ask every day : The following illegal constants are
A ‘a’ B .5 C 1.2E2.0 D ‘\025’
Catalog
Self addition and self subtraction and comma operators
Basic arithmetic operators :
+、-、*( Equivalent to the multiplication sign in Mathematics x)、\( Equivalent to division in Mathematics )、%( Mod )
division /
1.0/2.0=0.5
1.0/2=0.5
1/2.0=0.5
1/2=0Summary :a And b One of them is real , The result is real . if a And b Is an integer , The result is an integer .
Seeking remainder % Operator
The object of the remainder operation must be an integer
5%2=1
5%-2=-1
2%5=2Summary : The operation to find the remainder must be an integer
There are negative numbers , The sign of the remainder is consistent with the divisor .( And % The numbers on the left are the same )
Precedence and associativity of operators ,
priority : () > + ( Correct ) - ( Take the negative ) > *、/ 、% > +、-
associativity :
()*、/ 、% 、+、- From left to right
+ ( Correct ) - ( Take the negative ) From right to left 1
Data type conversion : Automatic conversion from low precision to high progress ( Last class cited the example of buying vegetables in the supermarket )
1.0/2=0.5000000Cast : High precision to low precision cast
analysis : If you go to the supermarket to buy vegetables , I bought a lot of vegetables and put them in a big bag. Later, I thought about it and put it together for environmental protection , Change a small bag. Because there are many dishes, you force the dishes into the small bag , But there are too many dishes to avoid being sent out of the bag .
form :( Type name ) expression
(int)5.2 // be equal to 5Assignment expression :
form : Variable name = expression
int a=10;The assignment is similar to filling a bottle with water .
priority : Only higher than the comma operator ( Second from the bottom )
associativity : From right to left
explain : According to the value of the priority expression , Let's assign it to the variable
Compound assignment operator
+=、-=、*=、/=、%=
priority : Only higher than the comma operator ( Second from the bottom )
associativity : From right to left
a+=3;//a=a+3
a*=2;//a=a*2
a%=1;//a=a%1Self addition and self subtraction and comma operators
form :++ Variable 、-- Variable 、 Variable ++、 Variable —
Pre value usage ++i --i
explain : First, add the variable i The value of the add 1 Or minus 1, Then use variables i Value .
Post value usage i++、i—
explain : First, we will use the variable i Value , Then add... To the value of the variable 1 Or minus 1
int i=1,j=1;
printf("%d,%d",++i,j++);// Input is 2,1
int i=1,j=1;
printf("%d,%d",--i,j--);// Input is 0,1The comma operator :
form : Expression 1 、 Expression two 、… expression n
explain : Evaluate from left to right , Expression n As the value of the entire comma expression
priority : The minimum
associativity : From left to right
int a=(1,2,3,4,5);//a=5;C Language priority table
priority | Operator | Name or meaning | Use form | Combination direction | explain |
1 | [] | The array subscript | Array name [ Constant expression ] | Left to right | -- |
() | parentheses | ( expression )/ Function name ( Formal parameter table ) | -- | ||
. | Member selection ( object ) | object . Member name | -- | ||
-> | Member selection ( The pointer ) | Object pointer -> Member name | -- | ||
2 | - | Negative operator | - expression | Right to left | Monocular operator |
~ | Bitwise negation operator | ~ expression | |||
++ | Self - increment operator | ++ Variable name / Variable name ++ | |||
-- | Self - subtracting operator | -- Variable name / Variable name -- | |||
* | Value operators | * Pointer to the variable | |||
& | Fetch address operator | & Variable name | |||
! | Logical nonoperator | ! expression | |||
( type ) | Cast | ( data type ) expression | -- | ||
sizeof | Length operator | sizeof( expression ) | -- | ||
3 | / | except | expression / expression | Left to right | Binocular operator |
* | ride | expression * expression | |||
% | remainder ( modulus ) | Integer expression % Integer expression | |||
4 | + | Add | expression + expression | Left to right | Binocular operator |
- | reduce | expression - expression | |||
5 | << | Move left | Variable << expression | Left to right | Binocular operator |
>> | Move right | Variable >> expression | |||
6 | > | Greater than | expression > expression | Left to right | Binocular operator |
>= | Greater than or equal to | expression >= expression | |||
< | Less than | expression < expression | |||
<= | Less than or equal to | expression <= expression | |||
7 | == | be equal to | expression == expression | Left to right | Binocular operator |
!= | It's not equal to | expression != expression | |||
8 | & | Bitwise AND | expression & expression | Left to right | Binocular operator |
9 | ^ | Bitwise XOR | expression ^ expression | Left to right | Binocular operator |
10 | | | Press bit or | expression | expression | Left to right | Binocular operator |
11 | && | Logic and | expression && expression | Left to right | Binocular operator |
12 | || | Logic or | expression || expression | Left to right | Binocular operator |
13 | ?: | Conditional operator | expression 1? expression 2: expression 3 | Right to left | Ternary operator |
14 | = | Assignment operator | Variable = expression | Right to left | -- |
/= | Assign value after division | Variable /= expression | -- | ||
*= | Multiply and assign | Variable *= expression | -- | ||
%= | Assign a value after taking the module | Variable %= expression | -- | ||
+= | Add and assign | Variable += expression | -- | ||
-= | Value after subtraction | Variable -= expression | -- | ||
<<= | Left shift assignment | Variable <<= expression | -- | ||
>>= | Right shift after assignment | Variable >>= expression | -- | ||
&= | Bitwise and post assignment | Variable &= expression | -- | ||
^= | Assign a value after bitwise XOR | Variable ^= expression | -- | ||
|= | Assign value by bit or after | Variable |= expression | -- | ||
15 | , | The comma operator | expression , expression ,… | Left to right | -- |
If there are mistakes , Welcome to correct !
边栏推荐
- PyQt5快速开发与实战 4.1 QMainWindow
- Programming style
- 07_ Service registration and discovery summary
- Rewrite the tensorrt version deployment code of yolox
- Storage and computing engine
- Some practical, commonly used and increasingly efficient kubernetes aliases
- 【云原生之kubernetes实战】在kubernetes集群下部署Rainbond平台
- 5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises
- How to deploy yolov6 with tensorrt
- As a VC, the auction house invested Web3 for the first time
猜你喜欢

Ctfshow ultimate assessment

Antdesign a-modal user-defined instruction realizes dragging and zooming in and out

npm install报错 强制安装

Wechat applet 5 - foundation strengthening (not finished)

A survey of robust lidar based 3D object detection methods for autonomous driving paper notes

linux安装和远程连接mysql记录

The execution sequence of async/await, macro tasks and micro tasks
![[interprocess communication IPC] - semaphore learning](/img/47/b76c329e748726097219abce28fce8.png)
[interprocess communication IPC] - semaphore learning

pollFirst(),pollLast(),peekFirst(),peekLast()

500 error reporting
随机推荐
PVT的spatial reduction attention(SRA)
坚果天气
MySQL transaction
Easy language programming: allow the screen reading software to obtain the text of the label control
Qdoublevalidator does not take effect solution
Deep understanding of Kalman filter (2): one dimensional Kalman filter
Antdesign a-modal自定义指令实现拖拽放大缩小
Summary of traversal methods
Wechat applet 5 - foundation strengthening (not finished)
Programming style
npm install报错 强制安装
Nut joke based on arkui ETS
500 error reporting
Openharmony Mengxin contribution Guide
CUDA programming-04: CUDA memory model
Rewrite the tensorrt version deployment code of yolox
ES6 new - function part
flex布局 (实战小米官网)
Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
08_ Service fusing hystrix