The if statement is a decision-making control structure in C. It executes a block of statements only when the given condition is true.
The if statement is a decision-making control structure in C. It executes a block of statements only when the given condition is true.
Here, the message is displayed because the condition
age >= 18 is true.
If the condition is true, the statements inside
the if block execute. If the condition is false,
the block is skipped.
A system may check a condition before performing an action. For example, a college portal can display a message when a student's attendance is at least 75%.
if (attendance >= 75) → display
"Eligible for exam".
Write a C program that accepts a student's attendance percentage and displays a message if the attendance is 75% or above.
if statement.
Check whether the attendance is greater than or equal to 75
using the >= operator.
The if statement evaluates a condition and executes
its block only when the condition is true. If the condition is
false, the program skips the block and continues with the next
statement.
Enter attendance percentage: 82
Eligible for exam.
The if statement does not provide an alternative block
when the condition is false. If an alternative action is required,
the if-else statement is used.
Watch a beginner-friendly explanation of the if statement in C programming.
A short handwritten-style revision sheet for the if statement will be provided here.
Use the mind map for quick revision of the if statement, condition and execution flow.