Conditionals & switch in C
From the C cheat sheet · Control Flow · verified Jul 2026
Conditionals & switch
if/else and switch.
c
// Quick Reference
if (x > 0) { ... } else if (x < 0) { ... } else { ... }
switch (n) {
case 1: ...; break;
default: ...;
}💡 switch needs a break per case, or control falls through to the next case.
⚡ Stacked case labels (case 6: case 7:) share one body - a clean way to group.
📌 switch works on integer/char/enum values, not on strings or floats.
🟢 if (ptr) tests non-NULL; if (n) tests non-zero - C treats 0 as the only false.
conditionalsswitch