CKTIS / C
conditional control flow — concept C23
`if` selects a branch from a scalar value: zero and a null pointer are false, other values true; `switch` compares a promoted integer value with `case` labels. `&&` and `||` short-circuit, but side effects inside conditions obscure sequencing and should be made explicit.
Version: C23
Syntax
conditional control flowif selects a branch from a scalar value: zero and a null pointer are false, other values true; switch compares a promoted integer value with case labels. && and || short-circuit, but side effects inside conditions obscure sequencing and should be made explicit.
Use if for validation and failure paths, and switch for complete handling of state codes or an enum. An early return often simplifies the invalid case; end each switch arm explicitly with break, return, or a documented fall-through.
Test boundary values: zero, a null pointer, range minimum and maximum, and an unknown enumeration value. In pointer && pointer->field, short-circuiting protects the dereference, but reversing the operands removes that protection.
Examples
#include <stdio.h>
int main(void) {
int stock = 3;
if (stock > 0) puts("available"); else puts("empty");
return 0;
}
Result
available
`if` selects a branch from a scalar value: zero and a null pointer are false, other values true; `switch` compares a promoted integer value with `case` labels. `&&` and `||` short-circuit, but side effects inside conditions obscure sequencing and should be made explicit.