operators priority in c

Operator Priority in C

In C, operators have different levels of precedence, which determines the order in which they are evaluated in an expression. Here is a list of the operator precedence in C, from highest to lowest:

  1. Parentheses: ()
  2. Postfix operators: ++, --
  3. Unary operators: +, -, !, ~, ++, --, *, &, sizeof, type cast
  4. Multiplicative operators: *, /, %
  5. Additive operators: +, -
  6. Shift operators: <<, >>
  7. Relational operators: <, >, <=, >=
  8. Equality operators: ==, !=
  9. Bitwise AND operator: &
  10. Bitwise XOR operator: ^
  11. Bitwise OR operator: |
  12. Logical AND operator: &&
  13. Logical OR operator: ||
  14. Conditional operator: ? :
  15. Assignment operators: =, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |=
  16. Comma operator: ,

Note: Operators with higher precedence are evaluated before operators with lower precedence. If operators have the same precedence, the associativity of the operators determines the order of evaluation. For example, the addition operator + and the subtraction operator - have the same precedence, but they are left associative, which means they are evaluated from left to right.

For more detailed information on operator precedence in C, you can refer to the C programming language specification or relevant programming resources.

[[SOURCE 1]]