CHAPTER 09 / 26
C If Else
Learn how to make decisions using if, else if and else.
01 — Syntax
if (condition) {\n // code\n} else {\n // code\n}02 — Example
#include <stdio.h>
int main() {
int age = 20;
if (age >= 18) {
printf("Adult");
} else {
printf("Minor");
}
return 0;
}03 — Important Points
- Conditions control which block executes.
- Use braces for clarity.
- Avoid confusing nested conditions.
04 — Common Mistakes
- Missing braces in complex conditions.
- Writing conditions that can never be true.
05 — Real-World Use
Conditional logic is used in validation, permissions, menus and business rules.
06 — Practice
Create a small program that demonstrates the main idea of C If Else.