C - If Else Statement
if-else
selects between two alternative blocks.
Learning Objectives
- Write
if-else
branches for binary choices.
Prerequisites
Example
#include <stdio.h>
int main(void) {
int score = 72;
if (score >= 60) {
printf("pass\n");
} else {
printf("fail\n");
}
}
Common Pitfalls
- Chained
if-else
can be harder to read thanswitch
when matching constants.
Checks for Understanding
- What prints when
score
is 59?
Show answers
fail