Branch and loop with if, else, for, while, and do-while. C treats zero as false and any non-zero value as true.
if and else
if (score >= 60) {
printf("pass\n");
} else {
printf("retry\n");
}
Loops
for (int i = 0; i < 5; i++) {
printf("%d\n", i);
}
C99 allows declaring the loop variable in the for header. Use break and continue like other C-family languages.
switch
switch works on integer types. Always include break unless fall-through is intentional.
Important interview questions and answers
- Q: Truth values in C?
A: Zero is false; any non-zero is true—do not assume only 0 and 1 after arbitrary expressions. - Q: Missing break in switch?
A: Execution falls through to the next case—sometimes intentional, often a bug.
Self-check
- Which loop runs the body at least once?
- What value is considered false in an if condition?
Interview prep
- Truth in C?
Zero is false; any non-zero is true—do not assume expressions yield exactly 0 or 1 unless normalized.
- switch fall-through?
Missing
breakexecutes subsequent cases—document intentional fall-through with comments.