C-language operators and their precedence summary tables
Round down ARROW one comma
Extraordinary increase or decrease in the length of needle
Three multiplication and division, four plus minus, five shifts
Don't forget the fish, it's in Shengfan's cook.
Small lights, big lights, lights, lights.
Father feed fish, uncle doubt, naked chicken also puzzled
13 Aunt, 14 father, funny, pocket to Low
“Round down ARROW one comma"refers to the 15th levelThe operator。 Where the circle refers to the operator (), which refers to the subscript operator [], the arrow refers to the struct member operator, and comma refers to the struct-body member operator,
“Extraordinary increase or decrease in the length of needle"refers to the 14th-level operator. Which does not refer to the logical operator!, where the bitwise counter operator is referred to. Increase or decrease refers to the self increment and decrement operator + + and-------------------------------------a type conversion operator (type), which refers to the pointer operator *, is the Long refers to the length operator sizeof
“Three multiplication and division, four plus minus, five shifts"refers to the 13th level to the 11th operator. 345 of them have no real meaning, just a level of distinction. You can also imagine that the third point is a level 13th operator. Multiplication and division are multiplying operators * and divide operators/, plus minus refers to the addition operator + and subtraction operator-, shift refers to the left shift operator << and right shift operator >>
“Don't forget the fish, it's in Shengfan's cook."refers to the remainder operator%, which is located in the cook of Shengfan, which means the multiplication operator, the division operator.
“Small lights, big lights, lights, lights."refers to the 10th level to the 9th operator. The small lamp headlamps refer to the relational operators <, <=, > and >=, which refers to the equals operator = =, which is not equal to the operator!=
“Father feed fish, uncle doubt, naked chicken also puzzled"refers to the 8th level to the 4th operator. Among them, dad feeding the fish is the 8th level of bitwise AND operator Uncle doubt refers to level 7th bitwise OR operator ^ and 6th level or operator | |, naked chickens are also confused by the level 5th, 4th logic and operators && and logic or operators | |
“13 Aunt, 14 father, funny, pocket to Low"refers to the 3rd level to the 1th operator. Among them, 13 aunt refers to the conditional operator?: (three has the double meaning, namely refers to?: The priority level is three, its operator type is also three eyes,? Is not aunt is puzzled?), 14 of the parent's 14 is meaningless, and the parent refers to the assignment operator =, + =, =, *=,/=,%=, >>=, <<=, &=, ^=, and |=, which refers to the 1th-level operator. Pocket to low refers to the level 15 operator to end.
Appendix: C-Language operators and precedence
Precedence operator meaning operator type combining direction
15 () parenthesis Monocular from left to right
[] subscript operator
-> point to struct member operator
, structural body Member operators
14! Logical non-operator from right to left
~ Bitwise inverse operator
+ + self-increasing operator
--Self-subtraction operator
-Minus sign operator
(type) type conversion operator
* pointer operator
& Address Operators
Sizeof length operator
13 * multiplication operator binocular from left to right
/Division Operator
% remainder operator
12 + addition operator
-Subtraction operator
Shift operator << left
>> Right Shift operator
<, <=, >, >= relational operators
9 = = equals operator
! = Not equal to operator
8 & Bitwise AND operator
7 ^ Bitwise XOR OR operator
6 | Bitwise OR operator
5 && Logic and operators
4 | | Logical OR operator
3? : Conditional operation Fusan from right to left
2 =, + =, =, *=,
/=,%=, >>=,
<<=, &=, ^=, |= assignment operator Binocular
1, comma operator binocular from left to right
②
Bracket Members First; Bracket operator [] () member operator. ->
Whole list Second; All monocular operators such as + +-+ (positive)-(negative) pointer operation *&
Multiplication and division Yusan, plus minus four; //this "remainder" means the remainder operation is%
shift five, relationship six; //shift operator:<< &NBSP;>>&NBSP, the relationship:> < >= <= , and so on
equals (and) unequal row seventh; //is == !=
bit with XOR or bitwise OR; //these are bitwise operations: bit with (&) or (^) bits or (|) &NBSP;&NBSP;&NBSP;&NBSP;&NBSP
"Three points World" eighty or ninety;
Logic //logical operators: | | and &&
12 and 11; //Note Order: Priority (| |) Bottom to priority (&&)
condition is higher than assignment, // The triple-Mesh operator priority is ranked to the 13 bit only than the assignment operator and "," the high///attention is given to the number of assignment operators!
comma operation-level minimum! //comma operator precedence
because the C language's operator precedence is not exactly the same as C + + (mainly by adding a few operators), So this formula is not entirely practical in C + +. But it should be compatible, you can compare their differences should be able to quickly grasp the priority of C + +!
((*strdest++=*strsrc++)!= ' "); :
Emphasis: + + after the increase of the operator priority is higher than *
1.*strdest++ equivalent to * (strdest++)
2. Since it is later, the order of execution is:
*strdest=*strsrc
strdest++ strsrc++//The order of the class is unknown
Compare *strdest with ' I '/that is, the value of the entire expression is the result of the comparison between *strdest and '
It is important to note that for an assignment expression, the value of the expression itself equals the value of the left-side subexpression.
Through the above in-depth analysis, we know that this expression completes the following functions:
1. For pointer strdest, STRSRC, assigns the value of the memory space that STRSRC refers to to the memory space referred to by strdest.
2. Determine whether the assigned value of the strdest refers to the amount of memory space is equal to 0.
3. For pointers strdest,strsrc, their values are added to 1, which means the next element.
That is, the expression implements the following three features:
1. For pointer strdest, STRSRC, assigns the value of the memory space that STRSRC refers to to the memory space referred to by strdest.
2. Determine whether the value of the memory space referred to in the assigned value is equal to 0 strdest.
3. For pointers strdest,strsrc, their values are added to 1, which means the next element.
C Language Operator table
operators are ranked up and down by priority size, and the operators in the same row have the same precedence. The second line is all unary operators.
Operator |
Explain |
Combination method |
() []->. |
Parentheses (functions, etc.), array, two struct members access |
From left to right |
! ~ ++ -- + - * & ( type ) sizeof |
negation, bitwise negation, increment, decrement, plus sign, Indirect, take address, type conversion, find size |
From right to left |
* / % |
Multiply, divide, take modulo |
From left to right |
+ - |
Plus, minus |
From left to right |
<< >> |
Move left, move right |
From left to right |
< <= >= > |
Less than, less than equal, greater than or equal, greater than |
From left to right |
== != |
Equal to, not equal to |
From left to right |
& |
Bitwise AND |
From left to right |
^ |
Per-bitwise XOR OR |
From left to right |
| |
by bit or |
From left to right |
&& |
Logic and |
From left to right |
|| |
Logical OR |
From left to right |
? : |
Conditions |
From right to left |
= += -= *= /= &= ^= |= <<= >>= |
Various assignments |
From right to left |
, |
Commas (order) |
From left to right |