Keywords cannot be used as variable names, function names, class names, or other user-defined identifiers..
These keywords are the fundamental building blocks that the C++ compiler uses to understand the structure and semantics of a program, such as declaring variables, defining functions, controlling flow, and object-oriented programming.
📘 Overview of C++ Keywords (as of C++20 / C++23)
The number of keywords in C++ has increased as the standard has evolved, from the early C++98 to C++11, C++14, C++17, C++20, and now C++23.
Below is a list of all keywords in the C++20 standard (approximately 95, including some context keywords), categorized for easier understanding and memorization.
⭐ 1. Basic Keywords (Common Core Keywords)
These are the most commonly used keywords, found in almost every C++ program:
|
Keyword |
Brief Description |
|---|---|
|
|
Declares an integer variable |
|
|
Declares a double-precision floating-point variable |
|
|
Declares a single-precision floating-point variable |
|
|
Declares a character variable |
|
|
Declares a boolean type (true/false) |
|
|
Indicates “no type” or “no return value” |
|
|
Allows the compiler to automatically deduce the variable type |
|
|
Indicates a constant that cannot be modified |
|
|
Static storage duration or class static member |
|
|
Declares a variable/function defined in another file |
|
|
(deprecated) Suggests the compiler place it in a register (generally ignored) |
|
|
Prevents compiler optimization (used for hardware registers, etc.) |
|
|
Defines an alias for a type (C style, C++ recommends using) |
|
|
Type aliasing, namespace introduction, etc. |
|
|
Defines a structure |
|
|
Defines a class |
|
|
Defines an enumeration type |
|
|
Defines a union |
|
|
Defines a namespace |
|
|
Defines a template (generic programming) |
|
|
Used in templates to refer to types |
|
|
Suggests the compiler inline the function |
|
|
Used to implement polymorphism (virtual functions) |
|
|
Explicitly indicates overriding a virtual function (C++11) |
|
|
Prevents a class from being inherited or a virtual function from being overridden |
|
|
Prevents implicit conversion of constructors |
|
|
Allows const member functions to modify that member |
|
|
Pointer to the current object |
|
|
Dynamically allocates memory |
|
|
Releases dynamically allocated memory |
|
|
Returns a value from a function |
|
|
Conditional statement |
|
|
Else branch of if |
|
|
Multi-branch selection |
|
|
Branch in switch |
|
|
Default branch in switch |
|
|
For loop |
|
|
While loop |
|
|
Do-while loop |
|
|
Exits a loop or switch |
|
|
Skips the current iteration, continues to the next |
|
|
Jump statement (not recommended) |
|
|
Exception handling try block |
|
|
Catches exceptions |
|
|
Throws exceptions |
|
|
Inline assembly (rarely used) |
⭐ 2. Type-related Keywords
|
Keyword |
Description |
|---|---|
|
|
Boolean type |
|
|
Character type |
|
|
Integer |
|
|
Short integer |
|
|
Long integer |
|
|
Signed type |
|
|
Unsigned type |
|
|
Single-precision floating point |
|
|
Double-precision floating point |
|
|
No type / No return value |
|
|
Wide character type (Unicode) |
|
|
UTF-8 character (C++20) |
|
|
UTF-16 character (C++11) |
|
|
UTF-32 character (C++11) |
|
|
Automatic type deduction |
|
|
Deduction of expression type (C++11) |
|
|
Type alias (replaces typedef) |
⭐ 3. Storage Class Specifiers
|
Keyword |
Function |
|---|---|
|
|
(old) Automatic storage duration (now used for type deduction) |
|
|
(deprecated) Suggests placing in a register |
|
|
Static storage duration / Static member of a class |
|
|
Declares external definition |
|
|
Thread-local storage (C++11) |
Note:
<span>auto</span>is primarily used for type deduction after C++11, rather than as a storage class.
⭐ 4. Function and Control Keywords
|
Keyword |
Usage |
|---|---|
|
|
Suggests inline function |
|
|
Compile-time constant / function (C++11) |
|
|
Indicates that a function does not throw exceptions (C++11) |
|
|
Virtual function, used for polymorphism |
|
|
Explicitly indicates overriding a virtual function (C++11) |
|
|
Prevents further overriding/inheritance (C++11) |
|
|
Return statement |
|
|
Gets the size of a type or object |
|
|
Specifies alignment (C++11) |
|
|
Gets the alignment requirement of a type (C++11) |
|
|
(non-standard, supported by some compilers) |
⭐ 5. Access Control and Class-related Keywords
|
Keyword |
Usage |
|---|---|
|
|
Public access |
|
|
Protected access |
|
|
Private access |
|
|
Friend function/class, can access private members |
|
|
Defines a class |
|
|
Defines a structure (default public) |
|
|
Defines a union |
|
|
Enumeration type |
⭐ 6. Templates and Generic Programming
|
Keyword |
Usage |
|---|---|
|
|
Defines a template |
|
|
Specifies type in a template |
|
|
Concept constraints (C++20 template constraints) |
|
|
Defines a concept (C++20) |
⭐ 7. Exception Handling
|
Keyword |
Usage |
|---|---|
|
|
Exception catch block |
|
|
Catches specific exceptions |
|
|
Throws exceptions |
|
|
Indicates no exceptions thrown (C++11) |
⭐ 8. Other and Advanced Features (C++11 and later)
|
Keyword |
Description |
|---|---|
|
|
Null pointer constant (C++11, replaces NULL) |
|
|
Compile-time constant expression/function (C++11) |
|
|
Function does not throw exceptions (C++11) |
|
|
Explicitly indicates overriding a virtual function (C++11) |
|
|
Prevents inheritance/overriding (C++11) |
|
|
Thread-local storage (C++11) |
|
|
Specifies alignment (C++11) |
|
|
Gets alignment requirement (C++11) |
|
|
Compile-time assertion (C++11) |
|
|
Deduction of expression type (C++11) |
|
|
Type deduction (more powerful since C++11) |
|
|
Type aliasing, template aliasing, namespace introduction, etc. |
|
|
Template concept (C++20) |
|
|
Template constraint conditions (C++20) |
|
|
Coroutine keyword (C++20 coroutines) |
|
|
Coroutine keyword (C++20 coroutines) |
|
|
Coroutine keyword (C++20 coroutines) |
⚠️ Coroutine-related keywords (
<span>co_await</span>,<span>co_yield</span>,<span>co_return</span>) are part of the advanced features added in C++20, used for writing asynchronous/coroutine-style code.
🚫 Notes:
-
Do not use C++ keywords as identifiers (such as variable names, function names, class names, etc.). For example, you cannot declare a variable named
<span>int</span>or<span>class</span>. -
Some words like
<span>main</span>are not keywords but are fixed names for the program entry function. -
Some words are keywords in certain contexts (known as context keywords, such as
<span>override</span>,<span>final</span>,<span>concept</span>), but can be used as identifiers elsewhere.
✅ Summary: List of C++ Keywords (Common Core)
Below are the most common and fundamental C++ keywords (approximately 30–40, suitable for beginners to focus on):
<span>int</span>,<span>double</span>,<span>float</span>,<span>char</span>,<span>bool</span>,<span>void</span>,
<span>if</span>,<span>else</span>,<span>for</span>,<span>while</span>,<span>do</span>,<span>switch</span>,<span>case</span>,<span>break</span>,<span>continue</span>,<span>return</span>,
<span>class</span>,<span>struct</span>,<span>public</span>,<span>private</span>,<span>protected</span>,
<span>new</span>,<span>delete</span>,<span>try</span>,<span>catch</span>,<span>throw</span>,
<span>namespace</span>,<span>using</span>,<span>typedef</span>,<span>auto</span>,<span>static</span>,<span>const</span>,<span>extern</span>,
<span>true</span>,<span>false</span>,<span>nullptr</span>(C++11),
<span>template</span>,<span>typename</span>,<span>inline</span>,<span>virtual</span>,<span>override</span>,<span>final</span>
📚 Want to see the complete list of keywords?
You can refer to the following resources:
-
C++ Keywords (cppreference.com)—— The most authoritative official documentation of C++ keywords, including all keywords and their introduced versions.
-
C++ Reference – All Keywords
🎯 Small Exercise (Optional)
Try this: Which of the following are C++ keywords? Which can be used as variable names?
<span>int</span>
<span>myVar</span>
<span>class</span>
<span>return</span>
<span>float</span>
<span>MyFunction</span>
<span>true</span>
<span>delete</span>
✅ Answers:
-
Keywords (cannot be used as variable names):
<span>int</span>,<span>class</span>,<span>return</span>,<span>float</span>,<span>true</span>,<span>delete</span> -
Can be used as variable/function names:
<span>myVar</span>,<span>MyFunction</span>