[Last modified : 2003.07.09]
From highest to lowest precedence [with either left-to-right ("L to R") or right-to-left ("R to L") associativity]:
function() [] -> .
! ~ ++ -- + - * & (type) sizeof
* / %
+ -
<< >>
< <= > >=
== !=
&
^
|
&&
||
?:
= += -= *= /= %= &= ^= |= <<= >>=
,
where:
function()
" refers to function invocation(type)
" refers to type casting+
, -
and *
have higher precedence than the corresponding binary operatorsNote that because the precedence of bitwise operators
&
, ^
and |
is lower than that of
the equality operators (==
and !=
),
bit-testing expressions must be parenthesised to give proper results:
if ((value & BITMASK) == REQUIREDBITS) {...
The equality (==
and !=
) and relational (<
, <=
, >=
and >
) operators all yield 0
for false and 1
for true.
#define DAYSPERWEEK 7
7
substituted for token
DAYSPERWEEK
. Note that in most cases, a better alternative is:const int DaysPerWeek = 7;
#define MAX(a, b) ((a) > (b)
? (a) : (b))
MAX(++i, ++j)
will increment either i twice and j once, or vice
versa.#define PATHFORMAT(d) #d "/%s"
PATHFORMAT(/etc)
will be expanded to:"/etc" "/%s"
"/etc/%s"
#define JOIN(a, b) a ## b
JOIN(var, 01)
will be expanded to:var01