owner sign in

2.4 C operator precedence and associativity

Throughout our C programs thus far, we have used operators like +, =, and ++ in expressions such as

x = 9 + 3;

We mean by this that 9 and 3 should be added together and the result assigned to variable x. We assumed that the + operator has higher precedence than the = operator. Our assumption was correct, but it's because the C language followed our intuition about operator precedence and associativity.

lists all C operators through the C99 standard in order of their precedence (highest to lowest).1 Operators within the same division have equal precedence.

Table 2.1: C operator precedence and associativity through C99 Community (2022).
Prec.OperatorDescriptionAssociativity
1++ --Postfix …

This is a preview. Read the full book in print or ebook — get it from MIT Press (ISBN 9780262548762).

Instructor with access? Instructor login.