[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]:

- [L to R]
`function`() [] -> . - [R to L]
`! ~ ++ -- + - * & (`

`type`) sizeof - [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]
`,`

where:

- "

" refers to function invocation`function`() - "
`(`

" refers to type casting`type`) - unary
`+`

,`-`

and`*`

have higher precedence than the corresponding binary operators

Note 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`

- Simple textual substitution.
`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`))- Simple textual substitution with parameter replacement. Note that, unlike
the corresponding function, the parameters and result may be any scalar type
or even pointers. Also in contrast to a function,
**a parameter may be evaluated more than once**, giving undesired effects:

`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"`

which will yield:`"/etc/%s"`

`#define JOIN(`

`a`,`b`)`a`##`b``JOIN(var, 01)`

will be expanded to:`var01`

RLR