HPlogo HP C/HP-UX Reference Manual: Workstations and Servers > Chapter 5 Expressions

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.

Table 5-1 “C Operator Precedence ” shows the rules of operator precedence in the C language. The table lists the highest precedence operators first. 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)

Table 5-1 C Operator Precedence

Operators

Grouping

() [] -> .

left to right

+ ! ~ ++ -- - * & sizeof (See note 1 below.)

right to left

(type)

right to left

* / %

left to right

+ -

left to right

<< >>

left to right

< <= > >=

left to right

== !=

left to right

&

left to right

^

left to right

|

left to right

&&

left to right

||

left to right

?:

right to left

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

right to left

,

left to right

 

1 Note that the +, -, *, and & operators listed in this row are unary operators.