What are precedence and associativity in C.

A operators

As befits a decent book, you will find some tables and lists in the appendix, such as the order of precedence of the operators, an ASCII code table, reserved keywords in C and the standard header files.


A.1 Precedence of the operators

The following table lists the operators of C and their associativity (the binding of the operands) in descending order. Operators of the same priority class have the same precedence.


operatorMeaning / nameAssociativity
1st priority

Increase after evaluation

left to right

Reduce after evaluation

Function call

Array element

Pointer to structure element

Element of a structure or union

2nd priority

Increase before evaluation

from right to left

Decrease before evaluation

logical negation

One's complement

unary minus

unary plus

address

Indirection

Size in bytes

Type conversion (Cast)

3rd priority

multiplication

left to right

division

Remainder of a division

4th priority

addition

left to right

subtraction

5th priority

bit by bit left shift

left to right

bitwise right shift

6. Priority

less than

left to right

less than or equal to

greater than

greater or equal

7. Priority

equal

left to right

unequal

8. Priority

bitwise AND

left to right

9. Priority

bitwise EXCLUSIVE-OR

left to right

10. Priority

bitwise OR

left to right

11. Priority

logical AND

left to right

12. Priority

logical OR

left to right

13. Priority

condition

from right to left

14. Priority

allocation

from right to left

compound assignments (arithmetic)

<<=, >>=, &=, ^=, |=

compound assignments (bitwise)

15. Priority

Comma operator

left to right




your opinion

How did you like the Openbook? We always look forward to your feedback. Please send us your feedback as an e-mail to [email protected]