The order is: 1. "()", ., etc.; 2.!, ~, -, *, &, etc.; 3. *, /, %; 4. Addition and subtraction operations; 5. "< ;<", ">>"; 6. <, >, etc.; 7. "==", "!="; 8. &; 9, ^; 10, |; 11. "&&" ;12. "||"; 13. "?:"; 14. Assignment operation, etc.
The operating environment of this tutorial: Windows 7 system, C 17 version, Dell G3 computer.
The priority order of operators in C language is as follows:
is divided into 15 priority levels:
1, parentheses [()], subscript operator [[ ]], component operator pointing to structure member operator [->], structure member operator [.];
2, logical NOT operator [!], bitwise negation operator [~], increment and decrement operators [ ] [ -- ], negative sign operator [-], type conversion operator [(type)], pointer operator and address operator [*] [&], Length operator [sizeof];
3, multiplication operator [*], division operator [/], remainder operator [%];
4, addition operator [ ] , Subtraction operator [-];
5. Left shift operator [<<], Right shift operator [>>];
6, Relational operator [ < 】【>】【<=】【 >= 】;
7. Equal operator [==], not equal operator [!=];
8 , Bitwise AND operator [&];
9. Bitwise XOR operator [^];
10. Bitwise OR operator [|];
11. Logical AND operator [&&];
12. Logical OR operator [||];
13. Conditional operator [?:];
14. Assignment operators [=] [/=] [*=] [%=] [ =] [-=] [<<=] [>>=] [&=] [^=] [ |=];
15. Comma operator [,].
Extended information:
Notation of operator precedence:
C language handles almost all basic functions except control statements and input and output Operations are treated as operators, which shows its wide range (for example, the assignment operator "=" is used as the assignment operator, and square brackets are used as the subscript operator).
Priority has nothing to do with the order of evaluation. For example, a b && b*c, although * has the highest priority, the evaluation order of this expression is from left to right. The priorities decrease from top to bottom, with the topmost operator having the highest priority and the comma operator having the lowest priority.
With the same priority, combine according to the associativity. The associativity of most operators is from left to right. Only three precedences are associative from right to left. They are unary operators, conditional operators, and assignment operators.
Basic priorities need to be remembered: pointers are optimal, and monocular operations are better than binocular operations. Such as plus and minus signs. Arithmetic operations are performed first, then shift operations, and finally bit operations. Logical operations are combined at the end.
Recommended tutorial: "C#"
The above is the detailed content of What is the precedence order of operators in C language?. For more information, please follow other related articles on the PHP Chinese website!