• Home
• Priority of Operator in C language

# Priority of Operator in C language

In the C programming language, operators have a priority order that determines the order in which they are evaluated in an expression. Operators with a higher priority are evaluated before operators with a lower priority.

Here is the priority order of operators in C, from highest to lowest:

1. () (parentheses)
2. [] (array subscript)
3. -> (structure pointer)
4. . (structure member access)
5. ! (logical NOT)
6. ~ (bitwise NOT)
7. ++ (increment)
8. — (decrement)
• (unary minus)
• (dereference)
10. sizeof
• (multiplication)
11. / (division)
12. % (modulo)
• (subtraction)
13. << (left shift)
14. (right shift)

15. < (less than)
16. <= (less than or equal to)
17. (greater than)

18. = (greater than or equal to)

19. == (equal to)
20. != (not equal to)
21. & (bitwise AND)
22. ^ (bitwise XOR)
23. | (bitwise OR)
24. && (logical AND)
25. || (logical OR)
26. ?: (conditional)
27. = (assignment)
29. -= (subtract and assign)
30. *= (multiply and assign)
31. /= (divide and assign)
32. %= (modulo and assign)
33. &= (bitwise AND and assign)
34. ^= (bitwise XOR and assign)
35. |= (bitwise OR and assign)
36. , (comma)

It is important to use parentheses appropriately when writing expressions in C to ensure that the operators are evaluated in the correct order. For example, in the following expression:

``a + b * c``

The multiplication (b * c) will be evaluated before the addition (a + …), because the multiplication operator has a higher priority than the addition operator. To change the order of evaluation, we can use parentheses:

``(a + b) * c``

In this case, the addition (a + b) will be evaluated before the multiplication (* c), because the parentheses have the highest priority and force the addition to be evaluated first.