Selected Help on ANSI C
Contents
See Also
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:
- Operators on the same line have the same precedence
- "
()" refers to a function call
- Unary
+, - and * have
higher precedence than the corresponding binary forms
- Because the precedence of bitwise operators
&, ^ and | is lower than that of
== and !=,
bit-testing expressions must be parenthesised to give proper results:
if ((value & BITMASK) == 0) {...
int *decl()
- function returning pointer to int
int (*decl)()
- pointer to function returning int
char **decl
- pointer to pointer to char
int (*decl)[42]
- pointer to array[42] of int
int *decl[42]
- array[42] of pointer to int
void *decl()
- function returning pointer to void
void (*decl)()
- pointer to function returning void
int (*(*x())[])()
- function returning pointer to array[] of pointer to function returning int
int (*(*x[7])())[4]
- array[7] of pointer to function returning pointer to array[4] of int
#define DAYSPERWEEK 7
- Simple textual substitution of
7 substituted for token
DAYSPERWEEK.
Note and 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 arithmetic 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"
- Macro call
PATHFORMAT(/usr/tmp) will be expanded to:
"/usr/tmp" "/%s"
which will be catenated to yield:
"/usr/tmp/%s"
#define JOIN(a, b) a ## b
- Macro call
JOIN(var, 01) will be expanded to:
var01
- The relational operators
<, <=,
>= and > all yield
0 if the specified relation is false and
1 if it is true.