C Programming • C Basics, Operators, Loops
C Programming / Control Structures: if

Control Structures: if

Notes 2 C Basics, Operators, Loops

The if statement is a decision-making control structure in C. It executes a block of statements only when the given condition is true.

Notes

Control Structure: if

The if statement is a decision-making control structure in C. It executes a block of statements only when the given condition is true.

💡 Example
int age = 20; if (age >= 18) printf("Eligible");

Here, the message is displayed because the condition age >= 18 is true.

Syntax of if Statement

if (condition) { statement; }
📌 Key Point

If the condition is true, the statements inside the if block execute. If the condition is false, the block is skipped.

How if Works

Condition ↓ TRUE → Execute if block ↓ Continue program FALSE → Skip if block ↓ Continue program

Real-World Example

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%.

💡 Example

if (attendance >= 75) → display "Eligible for exam".

Practical Example

Problem Statement

Write a C program that accepts a student's attendance percentage and displays a message if the attendance is 75% or above.

Learning Outcomes

  • Understand the basic use of the if statement.
  • Use a relational operator in a condition.
  • Execute a statement only when the condition is true.

Hint

Check whether the attendance is greater than or equal to 75 using the >= operator.

Theory

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.

Program

#include <stdio.h> int main() { float attendance; printf("Enter attendance percentage: "); scanf("%f", &attendance); // check whether attendance meets the required percentage if (attendance >= 75) printf("Eligible for exam. "); return 0; }

Expected Output

Enter attendance percentage: 82

Eligible for exam.

Note

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.

Important Exam Questions

Short Answer Questions

  1. What is an if statement in C?
  2. Write the syntax of the if statement.
  3. What happens when the condition of an if statement is false?
  4. Which operators can be used in an if condition?
  5. Write a simple example of an if statement.

Long Answer Questions

  1. Explain the if statement in C with syntax and example.
  2. Write a C program using if to check whether a student is eligible for an examination based on attendance.
🎥 Recommended Learning

Watch a beginner-friendly explanation of the if statement in C programming.

▶ Watch: if Statement in C — Hindi

📝 Handwritten Notes

A short handwritten-style revision sheet for the if statement will be provided here.

🧠 Mind Map

Use the mind map for quick revision of the if statement, condition and execution flow.