Notes / C / Conditions

Conditions (if / else) in C — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Conditions Conditional statements let your program make decisions — running different code depending on whether a condition is true or false.C offers if, else if, else, and the switch statement for choosing between many fixed options..

Syntax

syntax
if (condition) {
    // code
} else if (condition2) {
    // code
} else {
    // code
}

Example

c
#include <stdio.h>

int main() {
    int marks = 72;
    if (marks >= 90) {
        printf("Grade: A\n");
    } else if (marks >= 60) {
        printf("Grade: B\n");
    } else {
        printf("Grade: C\n");
    }
    return 0;
}

Output

outputGrade: B

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview "What happens if you forget break in a switch?" — execution falls through into the next case, which is a favorite interview trap.
Back to notes Read full lesson →