Selected Help on C

[Last modified : 2003.07.09]

Contents

See Also

Operators Precedence and Associativity

From highest to lowest precedence [with either left-to-right ("L to R") or right-to-left ("R to L") associativity]:

  1. [L to R] function() [] -> .
  2. [R to L] ! ~ ++ -- + - * & (type) sizeof
  3. [L to R] * / %
  4. [L to R] + -
  5. [L to R] << >>
  6. [L to R] < <= > >=
  7. [L to R] == !=
  8. [L to R] &
  9. [L to R] ^
  10. [L to R] |
  11. [L to R] &&
  12. [L to R] ||
  13. [R to L] ?:
  14. [R to L] = += -= *= /= %= &= ^= |= <<= >>=
  15. [L to R] ,

where:

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) {...

Value of Equality and Relational Expressions

The equality (== and !=) and relational (<, <=, >= and >) operators all yield 0 for false and 1 for true.

Preprocessing

#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