| Group | Operators |
|---|---|
| Postfix | [] () -> . ++ -- |
| Unary | ++ -- + - ! ~ * & sizeof |
| Multiplicative / additive | * / % + - |
| Shift | << >> |
| Relational / equality | < > <= >= == != |
| Bitwise | & ^ | |
| Logical | && || |
| Ternary / assign / comma | ? : = += … , |
Parenthesize mixed shifts, bitwise, and compares. n << 2 + 1 is n << (2 + 1). a & b == c is a & (b == c).
int before arithmetic.+, <, and friends.INT_MAX + 1 is undefined. Unsigned wrap is defined modulo 2^n./ toward zero (C99). % follows the dividend. Integer / 0 is undefined.+ concatenation. Adjacent string literals concatenate in translation: "a" "b" → "ab".unsigned n = 10;
int i = -1;
if (i < n) { /* often false — i converts to unsigned */ }
| Want | Use |
|---|---|
| Guard a dereference | p != NULL && p->n > 0 |
| Both sides always run | & | — and they are bits, not booleans |
| Flags / masks | & | ^ ~ << >> on unsigned |
| Logical not vs bitwise not | ! vs ~ |
if (p != NULL && p->n > 0) { }
unsigned can_read = flags & READ;
1 << 31 on a 32-bit signed int is undefined. Use 1u << 31.
n++ yields the old value then adds. ++n adds then yields the new value.i = i++ or a[i++] = i++. One modification per object between sequence points.sizeof ++n on a non-VLA int does not increment n.if.~ Good luck with your revision! ~