C language operator Priority Level

Source: Internet
Author: User

C language operator Priority Level

C language operator Priority Level

[Square brackets and arrows end with a full stop]
[Auto-incrementing auto-minus non-negative, needle strong address length]
[Multiplication, division, addition, subtraction, and shift again]
[Small, big, and so on]
[Octal and], [Seven differences], [six or], [five and], [four or], [three questions], [two assignments], [funny]

("[]" Indicates a level segment)

Note:

"Square brackets and arrows end with a full stop"
It refers to a 15th-level operator. The [square brackets] are "(), []", the [Arrow] refers to the "->" operator pointing to the struct member, and the [period] refers to the struct member operator ". ";

"Auto-incrementing auto-minus non-negative, needle strong address length"
It refers to a 14th-level operator. [Not] indicates the logical operator "!". [Inverse] refers to the bitwise inverse operator "~", [Negative] refers to the negative operator "-", [Needle] refers to the pointer operator "*", and [strong] refers to the forced type conversion operator, [address] refers to the address operator "&", and [length] refers to the length operator "sizeof ";

"Multiplication, division, addition, subtraction, and shift"
[Shift] refers to the Left shift operator "<" and right shift operator ">". The [addition] also includes the remainder operator "% ";

"Small, big, and so on"
[Small and so on] refers to operators ranging from 10th to 9th: <, <=,> and> =, [and so on] refers to operators equal to "= ", not equal to the operator "! = ";

"Eight and, seven are different, six or"
The "octal and" operator refers to the bitwise AND operator "&" of the 8th level, and the "Seven-bit" operator refers to the bitwise OR operator "^" of the 7th level ", the "six-digit" or "" operator is a 6th-level bitwise OR operator "| ";

"V and, 4 or"
[V.] refers to the 5th-Level Logic and operator "&", and [4 or] 4th-Level Logic or operator "| ";

"Three questions, two questions, one funny"
It refers to operators ranging from 3rd to 1st. Where [three doubts] refer to the condition operator "? : "(Three has a double meaning: that is, the priority is three, and its operator type is also three, the suspect is also"?" Meaning ), [binary Assignment] refers to the value assignment operators =, + =,-=, * =,/=, % =, >>=, <<=, & =, ^ =, and | =, [really funny] refers to the 1st-level "," operator. The real word is only required for statements.

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 ++!

===== Operator priority and combination Law (sorted from high to low) ====

Operator ...................................................... Combination Law

() []-> ................................................. From left to right

! ~ + + -- (Type) sizeof + -*&............ From right to left

*/% ...................................................... From left to right

+ -......................................................... From left to right

<> ................................................... From left to right

<=> = .......................................... From left to right

=! ................................................... From left to right

&............................................................ From left to right

^ ............................................................ From left to right

| ............................................................ From left to right

&&......................................................... From left to right

| ............................................................ From right to left

? :............................................................ From right to left

= + =-= * =/= % = <=> =... From left to right

Priority
Operator name or meaning description
1
[] Array subscript array name [constant expression] left to right
() Parentheses (expressions)/function names (parameter tables)
. Select (object) object for the member. member name
-> Member selection (pointer) object pointer-> member name

2
-Negative sign operator-right-to-left single object operator of the expression
(Type) Forced type conversion (data type) Expression
++ Auto-increment operator ++ variable name/variable name ++ single object Operator
-- Auto-subtraction operator -- variable name/variable name -- single object Operator
* Value operator * single object operator of pointer variable
& Bitwise operators & variable names single-object Operators
! Logical non-Operator! Single Object Operator
~ Bitwise inversion operator ~ Single Object Operator
Sizeof length operator sizeof (expression)

3
/Except expressions/expressions left-to-right binary Operators
* Multiplication expression * expression left-to-right binocular Operator
% Remainder (Modulo) integer expression/Integer expression binary operator

4
+ Add expression + expression left-right binocular Operator
-Subtraction expression-expression binary operator

5
<Left shift variable <expression left-to-right binary operator
> Shift right variable> expression binary operator

6
> Greater than expression> left-right binary operator
> = Expression greater than or equal to> = expression binocular Operator
<Less than expression <expression binary operator
<= Less than or equal to expression <= expression binary operator

7
= Equal to expression = expression left-to-right binary operator

! = Not equal to the expression! = Expression binary operator

8
& Bitwise and expression & Expression left-to-right binary operator

9
^ Bitwise OR expression ^ left-right binary operator

10
| Bitwise OR expression | left-right binary operator of the expression

11
& Logic and Expression & Expression left-to-right binary operator

12
| Logic or expression | left-to-right binary operator of the expression

13
? : Conditional operator expression 1? Expression 2: expression 3 right-to-left Operator

14
= Value assignment operator variable = expression right to left

/= Assign variable/= expression after Division

* = Assign variable after multiplication * = expression

% = Value variable % = expression after modulo operation

+ = Add and assign variable + = expression

-= Assign a variable after subtraction-= expression

<= Assign variable after left shift <= expression

>>= Variable assigned after right shift >>= expression

& = Bitwise AND postvalue variable & = expression

^ = Bitwise OR post-assigned variable ^ = expression

| = Bitwise OR post-value variable | = expression

15
, Comma operator expression, expression ,... Left-to-right sequence operation

Note:

Operators with the same priority are determined by the Union direction.

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.