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
#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
Valid age6. 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
1. What is another name for keywords in C++?
2. Which statement about C++ keywords is true?
3. Which of the following is a C++ keyword?
4. What happens if you try to name a variable `class`?
5. Which C++ standard introduced `nullptr` as a keyword?
Was this page helpful?
You May Also Like
Tokens in C++
Learn what tokens are in C++, the six kinds of tokens, and how the compiler breaks source code into them.
Identifiers in C++
Learn what identifiers are in C++, the naming rules the compiler enforces, and good naming conventions.
Data Types in C++
Learn the fundamental data types in C++ — int, float, double, char, bool, and void — with sizes, ranges, and examples.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics