Parentheses () have three uses:
- Grouping to control order of evaluation, or for clarity.
Eg, (a + b) * (c - d)
- After a function name to enclose parameters. Eg, x = sum(a, b);
- Around a type name to form a cast. Eg, i = (int)x;
Order of evaluation
- Higher precedence are done before lower precedence.
- Left to right among equal precedence except:
unary, assignment, conditional operators.
Abbreviations
i, j - integer (char, short, int, long) values.
m, n - numeric values (integers, floating-point).
b, c - int expr: 0=true, non-zero=false; x, y - any type.
s, t - string; a - array; p - pointer; f - field.
|
| Operator Precedence |
::
. [] -> (args) post ++ --
type_id dynamic_cast static_cast
cont_cast reinterpret_cast
unary + - * & pre ++ --
! ~ (type) new sizeof delete
->* .*
* / %
+ -
<< >>
< <= > >=
== !=
&
^
|
&&
||
?:
= += -= etc
throw
,
|
Remember only
- unary operators
- * / %
- + -
- comparisons
- && ||
- = assignments
Use () for all others
|
|