From highest to lowest precedence [associativity]:
() [] -> . [L to R] ! ~ ++ -- + - * & (type) sizeof [R to L] * / % [L to R] + - [L to R] << >> [L to R] < <= > >= [L to R] == != [L to R] & [L to R] ^ [L to R] | [L to R] && [L to R] || [L to R] ?: [R to L] = += -= *= /= %= &= ^= |= <<= >>= [R to L] , [L to R]
Notes:
()
" refers to a function call+
, -
and *
have higher
precedence than the corresponding binary forms&
, ^
and |
is lower than that of
==
and !=
, bit-testing expressions must be
parenthesised to give proper results:if ((value & BITMASK) == 0) {...
#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(/usr/tmp)
will be expanded to:"/usr/tmp" "/%s"
"/usr/tmp/%s"
#define JOIN(a, b) a ## b
JOIN(var, 01)
will be expanded to:
var01
<
, <=
,
>=
and >
all yield
0
if the specified relation is false and
1
if it is true.