Introduction to C language operators and their priority summary tables

Source: Internet
Author: User

Since the operator priority of C language is not exactly the same as that of C ++ (mainly adding several operators), this phrase cannot be fully used in C ++. but it should be compatible. You can compare their differences and quickly grasp the priority of C ++.

Introduction to C language operators and their priority summary tables

Arrow 1 down the circle
Extraordinary increase or decrease in strength and strength
Multiplication and division, addition and subtraction, and shift
Don't forget the fish. It's in the kitchen.
Small lamps, headlight lamps, etc.
Dad fed the fish, but he was confused.
Aunt 13th, Father 14th, funny, low

The "arrow at the bottom of a circle" refers to a 15th-level operator. In this example, the circle refers to the operator (), the subscript operator [], the arrow refers to the operator that points to the struct Member->, and the comma refers to the struct member operator,
"Extraordinary increase or decrease in strength and strength" refers to a 14th-level operator. Which does not refer to logical operators !, Which refers to the bitwise anti-operator ~, Increase or decrease refers to the auto-increment and auto-subtraction operators ++ and --, the rich operator refers to the minus operator-, and the strong operator refers to the type conversion operator (type ), the needle refers to the pointer operator *, the ground refers to the address operator &, And the length refers to the length operator Sizeof
"Three multiplication division, four addition and subtraction, and five shift" refer to operators ranging from 13th to 11th. Among them, there is no practical significance, but it is just a matter of differentiation level. You can also imagine that Level 3 refers to level 3 operators. Multiplication and division operators * and division operators/. addition and subtraction operators + and subtraction operators-and shift operators left shift operators <and Right Shift Operators>
"Never forget the fish. It is in the kitchen where the food is filled" refers to the remainder operator %, which is located in the kitchen where the food is filled, that is, together with the multiplication operator and division operator.
The period from small to 10th refers to operators ranging from 9th. The headlight is a relational operator <, <=,>, and> =, while the lamp is equal to or equal to the operator =! =
"Dad fed the fish and asked questions, and the Naked Chicken was confused" refers to operators ranging from 8th to 4th. Among them, Dad refers to the 8th level bitwise AND operator &, margin doubts refer to bitwise XOR operators of level 7th and bitwise OR operators of level 6th. |, bare chicken is also confused about the logic and operators of the 5th and 4th levels & and logic or Operators |
"Thirteen aunts, fourteen fathers, fifteen tease, full to low" refers to the operators from 3rd to 1st levels. Which of the following statements refer to the conditional operators? : (Three has a double meaning, that is? : The priority is three, and its operator type is also three ,? Isn't it confusing ?), The 14th of the 14th parent has no practical significance, the parent operator is the value assignment operator =, + =,-=, * =,/=, % =, >>=, <=, <=, ^=, and |=, the 15th hint refers to the 1st-level operator, and the lower-level operator refers to the 15th-level operator, ending.

Appendix: C language operators and priorities
Priority operator meaning operator type combination direction
15 () parentheses () from left to right)
[] Subscript operator
-> Pointer to struct member operators
, Struct member operators
14! Logical non-operator from right to left

~ Bitwise Inverse Operator
++ Auto-increment operator
-- Auto-subtraction Operator
-Minus sign Operator
(Type) type conversion Operator
* Pointer Operators
& Address Operators
Sizeof length Operator
13 * multiplication OPERATOR: left-to-right
/Division Operator
% Remainder Operator
12 + addition Operators
-Subtraction Operator
11 <left shift operator
> Right shift operator
10 <, <=,>,> = 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? : The conditional operators are displayed from the right to the left.

2 =, + =,-=, * =,
/=, % =, >>=,
<<=, & =, ^ =, | = Binary value assignment operator
1. the comma operator is left-to-right.


Parentheses are the first member. // brackets operator [] () member operator.->
Second for all single object; // All single object operators, such as ++ -- + (positive)-(negative) pointer operations *&
Multiply the remainder three and add or subtract four; // This "remainder" refers to the remainder operation, that is, %
Shift 5, relation 6; // shift operator: <>>, relation: ><>=
Equals (and) to the seventh row; // that is, =! =
Bitwise AND exclusive or bitwise OR; // these operations are bitwise operations: bitwise AND (&) exclusive or (^) bitwise OR (|)
"Three parts of the World" 80 or 90;
Logical or heel and // logical operators: ||and &&
12 and 11; // attention sequence: Priority (|) at the bottom of priority (&&)
When the condition is higher than the value assignment, // the priority of the Three-object operator is exceeded to 13 BITs, which is only equal to the value assignment operator and "," High // note that there are many value assignment operators!
The lowest comma operation level! // The comma operator has the lowest priority.

Since the operator priority of C language is not exactly the same as that of C ++ (mainly adding several operators), this phrase cannot be fully used in C ++. but it should be compatible. You can compare their differences and quickly grasp the priority of C ++!

(* StrDest ++ = * strSrc ++ )! = '');:
Key points: the priority of the ++ post-increment operator is higher *
1. * strDest ++ is equivalent to * (strDest ++)
2. The execution sequence is as follows:

* StrDest = * strSrc
StrDest ++ strsrc ++ // Unknown Order
Compare * strDest with ''// that is, the value of the entire expression is the comparison result of * strDest ''.

It is worth noting that for a value assignment expression, the value of the expression itself is equal to the value of the Left subexpression.

Through the above in-depth analysis, we know that this expression has completed the following functions:

1. For the strDest and strSrc pointers, assign the value of the memory space referred to by strSrc to the memory space referred to by strDest.

2. Determine whether the memory space specified by strDest after the assignment is equal to 0.

3. For the strDest and strSrc pointers, their values are respectively added with 1, pointing to the next element.

That is, the expression implements the following three functions:

1. For the strDest and strSrc pointers, assign the value of the memory space referred to by strSrc to the memory space referred to by strDest.

2. Determine whether the value of the memory space referred to by strDest after the value assignment is equal to 0.

3. For the strDest and strSrc pointers, their values are respectively added with 1, pointing to the next element.

C language operator table

Operators are arranged from top to bottom according to their priority values. operators in the same row have the same priority. The second line is all unary operators.
 

Operator Explanation Combination Method
() []->. Parentheses (functions, etc.), arrays, two types of structure member access From left to right
! ~ ++ -- +-

* & (Type) sizeof

Negative, bitwise negative, incremental, reduced, positive and negative,

Indirect, address fetch, type conversion, and Size Estimation

From right to left
*/% Multiplication, division, modulo From left to right
+- Add, subtract From left to right
<> Left shift, right shift From left to right
<<=>=> Less than, less than or equal to, greater than or equal to, greater From left to right
=! = Equal to, not equal From left to right
& Bitwise AND From left to right
^ Bitwise OR From left to right
| By bit or From left to right
&& Logic and From left to right
| Logic or From left to right
? : Condition From right to left
= + =-= * =/=

<=>>=

Various assignments From right to left
, Comma (Order) From left to right

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.