CS 150 Introduction to C++ Programming - Spring 1998 |
|---|
[ Home | Lecture Notes| WebTutor | WebTutor Site Map]
Arithmetic expressions can be ambiguous if there is more than one way to perform the calculation. For instance, what is the value of the expression
5+4*3
Is it 17(5 + 12) or is it 27(9*3)? To solve this problem,
arithmetic expressions are evaluated according to certain rules
such as precedence and grouping order. Precedence refers to the
priority given to different arithmetic operators (i.e. which ones
will be done first).
For C++, the precedence of operators is
| Parenthesis | () |
| Multiplicative Group | * / % |
| Additive Group | + - |
For more details see page 94, or A1-2 in the text
For operators of the same precedence, the order of evaluation is
left to right.