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 C++ conditional statements work exactly like C's, with the bonus that conditions now naturally evaluate to a real bool instead of just an integer convention..

Syntax

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

Example

cpp
#include <iostream>
using namespace std;

int main() {
    int marks = 72;
    if (marks >= 90) {
        cout << "Grade: A" << endl;
    } else if (marks >= 60) {
        cout << "Grade: B" << endl;
    } else {
        cout << "Grade: C" << endl;
    }
    return 0;
}

Output

outputGrade: B

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Be ready to compare switch vs a chain of if/else if — switch is often faster and cleaner for many discrete values.
Back to notes Read full lesson →