Decision Making & Control Statements in C
Control execution flow using if, if-else, nested if-else, else-if ladders, and switch-case statements with break & default.
ifstatements evaluate expressions: any non-zero value is treated as true, 0 is false.switch-caseis optimized by compilers into jump tables for fast multi-way branching.- The
breakstatement prevents fallthrough to subsequent case blocks in aswitch. - The
defaultblock handles any value that doesn't match a listed case.
Conditional Statements (if, if-else, else-if)
In C, conditionals evaluate any expression to either 0 (False) or non-zero (True).
Writing `if (x = 5)` instead of `if (x == 5)` assigns 5 to x! Because 5 is non-zero, this condition is always true. Pro tip: Use Yoda conditions like `if (5 == x)` so the compiler errors out if you accidentally type a single `=`.
The switch-case Statement
The switch statement provides an elegant alternative to lengthy else-if chains when testing an integer or character variable against multiple constant values.
Test Your Understanding
Reinforce core concepts with interactive multiple-choice questions, live coding challenges, and top technical interview questions.
Your Current Score
0 / 1 correct(0 attempted)
What happens if you omit the 'break' statement in a switch-case block?
Beginner