HPlogo HP C/HP-UX Reference Manual: Version A.05.55.02 > Chapter 5 Expressions and Operators

Operator Precedence

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Index

Precedence is the order in which the compiler groups operands with operators. The C compiler evaluates certain operators and their operands before others. If operands are not grouped using parentheses, the compiler groups them according to its own rules.

The following lists C operator precedence in highest to lowest precedence:

Table 5-14 C Operator Precedence

Class of operator

Operators

Grouping

primary

() [] -> .

left to right

unary

(type casting)

sizeof

& (address of)

* (dereference)

- (reverse sign)

~ !

++ --

right to left

multiplicative

* / %

left to right

additive

+ -

left to right

shift

<< >>

left to right

relational

< <= > >=

left to right

equality

== !=

left to right

bitwise AND

&

left to right

bitwise XOR

^

left to right

bitwise OR

|

left to right

logical AND

&&

left to right

logical OR

||

left to right

conditional

?:

right to left

assignment

= += -= *=
/= %= >>= <<=
 &= ^= |=

right to left

comma

,

left to right

 

Precedence among Operators of Same Class

Most operators group from the left to the right but some group from the right to the left. The grouping indicates how an expression containing several operators of the same precedence will be evaluated. Left to right grouping means the expression

a/b * c/d

behaves as if it had been written:

(((a/b)*c)/d)

Likewise, an operator that groups from the right to the left causes the expression

a = b = c

to behave as if it had been written:

a = (b = c)

© Hewlett-Packard Development Company, L.P.