100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
C++

Keywords in C++

Learn what keywords are in C++, why they are reserved, and see the most commonly used ones with examples.

BasicsBeginner6 min readJul 7, 2026
Analogies

1. Intro

Keywords are words that already have a fixed, predefined meaning in the C++ language. The compiler reserves them for specific purposes — declaring data types, controlling program flow, defining classes, and more — so they cannot be used as ordinary names for variables, functions, or classes.

🏏

Cricket analogy: The word 'six' on a scoreboard always means the specific event of clearing the boundary on the full — you can't repurpose it to mean a player's name, just as C++ reserves keywords like int for their fixed compiler meaning.

Keywords are also called "reserved words" for exactly this reason: they are reserved by the language itself and off-limits as identifiers.

2. Syntax

Keywords are always written in lowercase and used exactly as the language defines them — you cannot alter their spelling or case. Some of the most frequently used C++ keywords include:

🏏

Cricket analogy: Umpire signals are standardized exactly — a raised finger always means 'out', never a variant gesture — just as C++ keywords must be typed lowercase and spelled exactly as the standard defines, like return never Return.

  • Data types — int, float, double, char, bool, void
  • Control flow — if, else, switch, case, for, while, do
  • Functions — return, void
  • Classes & objects — class, public, private, protected, this, new, delete
  • Storage & qualifiers — const, static, extern, volatile
  • Others — true, false, namespace, using, try, catch

3. Explanation

Because keywords already carry meaning to the compiler, trying to use one as a variable name — for example int class = 5; — produces a compile-time error. This is a deliberate design choice: it prevents ambiguity between language syntax and programmer-defined names.

🏏

Cricket analogy: You can't rename a bowler's delivery 'No-ball' as a nickname on the team sheet because that word already has a fixed meaning to the umpire — just as int class = 5; fails to compile because class already means something to the compiler.

The exact set of keywords is fixed by the C++ standard and can grow slightly between standard revisions (for example, nullptr, constexpr, and auto gained special reserved meaning in C++11 and later). Good compilers will flag any attempt to redefine a keyword immediately, which is why IDEs typically highlight keywords in a distinct color.

🏏

Cricket analogy: The ICC occasionally adds new official terms to the rulebook, like the 'Impact Player' rule introduced in newer T20 formats, just as C++11 added new reserved keywords like nullptr and constexpr to the standard.

4. Example

cpp
#include <iostream>
using namespace std;

int main() {
    int age = 20;        // 'int' and 'return'-style words are keywords
    const int MAX = 100; // 'const' is a keyword

    if (age < MAX) {     // 'if' is a keyword
        cout << "Valid age" << endl;
    }

    return 0;            // 'return' is a keyword
}

5. Output

text
Valid age

6. Key Takeaways

  • Keywords are reserved words with a fixed, compiler-defined meaning.
  • They cannot be used as identifiers (variable, function, or class names).
  • Keywords are always lowercase and must be spelled exactly as defined.
  • The keyword set is fixed by the C++ standard and can grow with newer standard versions.

Practice what you learned

Was this page helpful?

Topics covered

#CStudyNotes#Programming#KeywordsInC#Keywords#Syntax#Explanation#Example#StudyNotes#SkillVeris#ExamPrep