C If … Else

C Tutorial

🔀 C if...else Statement (Beginner → Advanced)

In C language, the if...else statement is used to make decisions based on conditions.
It allows your program to execute different blocks of code depending on whether a condition is true or false.


1️⃣ What is if...else?

if...else is a conditional control statement used to control program flow.


2️⃣ Basic if Statement ⭐


 

✔ Executes only when condition is true


3️⃣ if...else Statement


 

✔ One block executes, the other is skipped


4️⃣ if...else if...else Ladder ⭐

Used when there are multiple conditions.


 

✔ Conditions are checked top to bottom


5️⃣ Nested if...else 🔁

An if inside another if.


 

✔ Used for complex decision making


6️⃣ if Without Braces ⚠️

if (x > 0)
printf("Positive");

✔ Only one statement is controlled
⚠️ Risky – braces recommended


7️⃣ Logical Operators in if Conditions ⭐

if (age >= 18 && age <= 60) {
printf("Eligible");
}

✔ Combines multiple conditions


8️⃣ if vs switch

Featureif...elseswitch
Condition typeAny expressionConstant values
Range checks✅ Yes❌ No
FlexibilityHighMedium

9️⃣ Common Mistakes ❌

❌ Using = instead of ==
❌ Missing braces in nested conditions
❌ Wrong condition order
❌ Forgetting else case


📌 Interview Questions (Must Prepare)

  1. Difference between if and if...else

  2. What is else if ladder?

  3. Can if exist without else?

  4. Difference between nested if and else if

  5. Which is better: if...else or switch?


🔥 Real-Life Use Cases

  • Login validation

  • Grade calculation

  • Menu selection

  • Eligibility checks

  • Error handling


✅ Summary

if...else controls decision making
✔ Supports multiple and nested conditions
✔ Logical operators improve power
✔ Fundamental for all C programs & interviews

You may also like...