Home >Backend Development >C#.Net Tutorial >What is the order of precedence of operators in C language?

What is the order of precedence of operators in C language?

下次还敢
下次还敢Original
2024-05-08 12:00:27524browse

C language operator precedence sequence: unary operators multiplication and division operators addition and subtraction operators displacement operators relational operators equality operators logical operators conditional operators assignment operators

What is the order of precedence of operators in C language?

C language operator precedence sequence

In C language, the precedence of operators determines their order in an expression The order of execution. The higher the operator precedence, the first it is executed.

The following is the order of precedence of C language operators from high to low:

1. Unary operator

  • & (address Address)
    • (dereference)
    • ##(take a positive number)
    • (Take a negative number)
  • ! (Logical NOT)
  • ~ (Bit NOT)
  • (Previous Increment)
  • -- (pre-decrement)

2. Multiplication and division operators

    • (Multiplication)
  • / (Division)
  • % (Remainder)

3. Addition and subtraction Operator

    • (addition)
    • (subtraction)

4. Bit shift operator

    << (left shift)
  • ##( Shift right)
5. Relational operator

< (less than)
  • (Greater than)
  • <= (Less than or equal to)
  • = (Greater than or equal to)
  • ##6. Equality operator

##== (equal to)

!= (not equal to)
  • 7 . Logical operators

&& (logical AND)

|| (logical OR)
  • ! (logical NOT)
  • 8. Conditional operator (ternary operator)

? :

  • 9. Assignment operator

= (assignment)

= (plus assignment)
  • -= (subtraction assignment)
  • *= (multiplication assignment)
  • /= (division assignment)
  • %= (remainder assignment)
  • <<= (left shift assignment)
  • = (right shift assignment)
  • &= (logical AND assignment)
    |= (logical OR assignment)
  • ^= (EXIST Or assignment)
  • Note:

Operators with the same priority are executed in order from left to right.

You can use parentheses to change the execution order of operators.

The above is the detailed content of What is the order of precedence of operators 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