Home  >  Article  >  What is the operator precedence rule in C language?

What is the operator precedence rule in C language?

清浅
清浅Original
2019-03-19 13:16:2462763browse

C language operator priority order is: bracket members first; all single items second; multiplication and division remainder three, addition and subtraction four; shift five, relationship six; equality (and) inequality ranking Seven; bitwise AND, XOR and bitwise OR, "three-thirds of the world" eighty or ninety; logical OR and AND, twelve and eleven; condition is higher than assignment; comma operation level is the lowest.

What is the operator precedence rule in C language?

There are fifteen priorities in total:

## 2(Type)--##exceptexpression/expressionleft to rightBinary operator*Multiplyexpression*expressionbinary operator%Remainder (modulo)Integer expression/integer expressionBinary operation Symbol4plusExpression expressionLeft to right##> is greater than Expression>ExpressionLeft to right##less thanexpression

binary operator
<=less than or equal toExpression< ;=expressionbinary operator##7!=##&&Logic andExpression&&expressionLeft to rightBinary operator12||##1314##Assignment after bitwise ANDVariable&=Expression^=Assignment after bitwise XORVariable^=expression|=##15

Priority

Operator

Name or meaning

Used form

Combined direction

Description

1

[]

Array subscript

Array name [constant expression]

Left to right

()

Parentheses

## (expression)/function name (parameter list)

.

Member Select(object)

Object.Member name

##->

Member selection (pointer)

Object pointer->Member name

##-

Negative operator

-expression

Right to left

Unary operator

Forced type conversion

(data type) expression

Increment operator

Variable name/variable name

Single Operator

Decrement operator

--Variable name/Variable name--

Unary operator

*

Value operator

*Pointer variable

Unary operator

&

Get address operator

& variable name

Unary operator

!

Logical NOT operation Symbol

!Expression

Unary operator

~

Bitwise negation operator

~Expression

Unary operator

sizeof

length operator

sizeof(expression)

##3

/

Binary Operator

-

Minus

Expression-expression

Binary operator

5

<<

Shift left

Variable<

Left to right

Binary operator

##>>

Shift right

Variable>>Expression

Binary operator

6

Binary Operator

>=

Greater than or equal to

expression>=expression

binary operator

# #<

==

equal to

expression==expression

left to right

Binary operator

is not equal to

expression!= expression

binary operator

8

&

## bitwise and

Expression&expression

Left to right

Binary operator

9

^

Bitwise XOR

Expression^Expression

Left to right

Binary operator

10

|

bitwise OR

expression|expression

Left to right

Binary operator

##11

##Logical or

Expression||Expression

Left to right

Binary operator

?:

Conditional operator

Expression 1 ? Expression 2: Expression 3

right to left

ternary operator

=

Assignment operator

Variable = expression

right to left

/=

Assignment after division

Variable/=Expression

*=

Multiply and assign value

Variable*=expression

%=

Assign a value after taking the modulus

Variable% =Expression

=

Assignment after addition

Variable = expression

-=

Assignment after subtraction

Variable-=Expression

<<=

Assign value after left shift

Variable<<=expression

#>>=

Assign value after right shift

Variable>>=expression

&=

##Assignment after bitwise OR

Variable|=Expression

,

Comma operator

Expression, expression,...

Left to right

Operations sequentially from left to right

##Instructions:

For operators with the same priority, the order of operations is determined by the combination direction.

Function:

    ##Bracket members no. 1; //Bracket operator []() Member operator. ->
  • All unary operators Second; //All unary operators such as, --, ( Positive), -(negative), pointer arithmetic*, &
  • multiplication and division with remainder three, addition and subtraction four; //This "remainder" refers to the remainder operation, that is, %
  • Shift five, relationship six; //Shift operator: << >>, relationship: > < >= <= etc.
  • Equal (and) is not equal to the seventh; //that is, == and!=
  • bitwise AND, XOR and bitwise OR; //These are all It is a bitwise operation: Bitwise AND (&) XOR (^) Bitwise OR (|)
  • "三三天下"八九十;

  • Logical OR and AND ; ;
  • The condition is higher than the assignment, //The ternary operator's priority is ranked 13th, only higher than the assignment operator and ","

    The comma operation level is the lowest! //Comma Operator has the lowest precedence
  • #

The above is the detailed content of What is the operator precedence rule in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn