Chapter 3 C Operators and Control Statements

Almost every program needs to perform calculations and process data, otherwise the program will be meaningless. To perform operations, you need to specify the operators that can be used.
The range of operators in C language is very wide, and almost all basic operations except control statements and input and output are treated as operators.

Operator Classification 1

In addition to arithmetic operators, C also provides other operators, which fall into the following categories:
Insert image description here
Insert image description here

& If both the bitwise and binary sign bits are 1, it is 1
| If one of the bitwise or binary sign bits is 1, it is 1
^ If the bitwise XOR binary sign bit is the same, it is 0, if it is different, it is 1
~bitwise negation Binary sign bit, 1 changes to 0, 0 changes to 1

Shift unsigned right, fill the high bit with 0, and overflow the low bit. There is a signed number, and the high-order bit is supplemented with the sign bit.
<<Shift left, high bit overflows, low bit filled with 0

Comma operator A,B. The result is B

Operator Classification 2

Unary operator

++a

binary operator

a+b;
a += b;

ternary operator

x ? a : b;

priority

Insert image description here
Insert image description here

control statement

①if()…else…
②for()… (loop statement)
③ while()… (loop statement)
④ do…while() (loop statement)
⑤ continue (end this loop statement)
⑥ break (stop execution of switch or loop) statement)
⑦ switch (multi-branch selection statement)
⑧ return (return statement from function)
⑨ goto (turning statement, goto statement is basically not used in structured programs)

Guess you like

Origin blog.csdn.net/LookOutThe/article/details/133412082