HP 3000 Manuals

Operator Precedence [ HP C/iX Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Reference Manual

Operator Precedence 

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  shows the rules of operator precedence in the C language.
Table 5-1  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                |                right to left                |
| (See note 1 below.)                         |                                             |
|                                             |                                             |
---------------------------------------------------------------------------------------------
|                                             |                                             |
| (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.



MPE/iX 5.0 Documentation