search
HomeCommon ProblemWhat is the operator precedence rule in C language?

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

#>>=

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: > =

    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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools