Operator Precedence in C
Precedence decides which operator grabs operands first without parentheses: * and / before + and -, comparisons before && before ||, assignment nearly last. C has over a dozen levels plus associativity for ties, and nobody memorizes all of them reliably.
Know the big five (! and unary first, then *//%, then +-, then comparisons, then logicals, then assignment last) and parenthesize everything else. Explicit parentheses cost nothing at run time and convert precedence puzzles into obviously-correct code.
Arithmetic first
2 + 3 * 4 is 14, not 20 — multiplicative binds tighter than additive, exactly like school math.
Comparisons before logicals
a < b && c < d groups as (a < b) && (c < d) — relational outranks && and ||, so range tests read naturally.
Assignment binds loosest
x = a + b means x = (a + b) — assignment happens after nearly everything on its right.
When in doubt, parenthesize
Shifts vs arithmetic, ternaries, and bitwise-vs-comparison mixes (x & 1 == 1 parses as x & (1==1)) are classic traps parentheses erase.
#include <stdio.h> int main(void) { int r1 = 2 + 3 * 4; int r2 = 5 > 3 && 2 > 4; int r3 = (2 + 3) * 4; printf("%d, %d, %d\n", r1, r2, r3); return 0;}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in C yourself — building beats watching.