The if-else statement is a decision-making control structure in C. It executes one block of statements when a condition is true and another block when the condition is false.
The if-else statement is a decision-making control structure in C. It executes one block of statements when a condition is true and another block when the condition is false.
If marks are 40 or more, the program displays
Pass; otherwise, it displays Fail.
A college result system can check whether a student has passed or failed based on the marks obtained.
marks >= 40 → Pass
Otherwise → Fail
Write a C program that accepts a student's marks and displays whether the student has passed or failed. A student is considered passed if the marks are 40 or above.
Use marks >= 40 as the condition.
Display Pass when it is true and
Fail otherwise.
The if-else statement provides two possible execution
paths. If the condition is true, the if block executes;
otherwise, the else block executes.
Enter marks: 72
Pass.
The else block executes only when the condition in the
if statement is false. The two branches provide
alternative outcomes for the same condition.
| if | if-else |
|---|---|
| Provides one decision path. | Provides two alternative paths. |
| Executes a block only when condition is true. | Executes one of the two blocks. |
| No alternative block is required. | Contains an else block. |
if → condition true
if-else → condition true OR condition false
Watch a beginner-friendly explanation of the if-else statement in C programming.
A short handwritten-style revision sheet for if-else will be provided here.
Use the mind map for quick revision of condition, if branch and else branch.