Overview of C++ Keywords

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

<span>int</span>

Declares an integer variable

<span>double</span>

Declares a double-precision floating-point variable

<span>float</span>

Declares a single-precision floating-point variable

<span>char</span>

Declares a character variable

<span>bool</span>

Declares a boolean type (true/false)

<span>void</span>

Indicates “no type” or “no return value”

<span>auto</span>

Allows the compiler to automatically deduce the variable type

<span>const</span>

Indicates a constant that cannot be modified

<span>static</span>

Static storage duration or class static member

<span>extern</span>

Declares a variable/function defined in another file

<span>register</span>

(deprecated) Suggests the compiler place it in a register (generally ignored)

<span>volatile</span>

Prevents compiler optimization (used for hardware registers, etc.)

<span>typedef</span>

Defines an alias for a type (C style, C++ recommends using)

<span>using</span>

Type aliasing, namespace introduction, etc.

<span>struct</span>

Defines a structure

<span>class</span>

Defines a class

<span>enum</span>

Defines an enumeration type

<span>union</span>

Defines a union

<span>namespace</span>

Defines a namespace

<span>template</span>

Defines a template (generic programming)

<span>typename</span>

Used in templates to refer to types

<span>inline</span>

Suggests the compiler inline the function

<span>virtual</span>

Used to implement polymorphism (virtual functions)

<span>override</span>

Explicitly indicates overriding a virtual function (C++11)

<span>final</span>

Prevents a class from being inherited or a virtual function from being overridden

<span>explicit</span>

Prevents implicit conversion of constructors

<span>mutable</span>

Allows const member functions to modify that member

<span>this</span>

Pointer to the current object

<span>new</span>

Dynamically allocates memory

<span>delete</span>

Releases dynamically allocated memory

<span>return</span>

Returns a value from a function

<span>if</span>

Conditional statement

<span>else</span>

Else branch of if

<span>switch</span>

Multi-branch selection

<span>case</span>

Branch in switch

<span>default</span>

Default branch in switch

<span>for</span>

For loop

<span>while</span>

While loop

<span>do</span>

Do-while loop

<span>break</span>

Exits a loop or switch

<span>continue</span>

Skips the current iteration, continues to the next

<span>goto</span>

Jump statement (not recommended)

<span>try</span>

Exception handling try block

<span>catch</span>

Catches exceptions

<span>throw</span>

Throws exceptions

<span>asm</span>

Inline assembly (rarely used)

⭐ 2. Type-related Keywords

Keyword

Description

<span>bool</span>

Boolean type

<span>char</span>

Character type

<span>int</span>

Integer

<span>short</span>

Short integer

<span>long</span>

Long integer

<span>signed</span>

Signed type

<span>unsigned</span>

Unsigned type

<span>float</span>

Single-precision floating point

<span>double</span>

Double-precision floating point

<span>void</span>

No type / No return value

<span>wchar_t</span>

Wide character type (Unicode)

<span>char8_t</span>

UTF-8 character (C++20)

<span>char16_t</span>

UTF-16 character (C++11)

<span>char32_t</span>

UTF-32 character (C++11)

<span>auto</span>

Automatic type deduction

<span>decltype</span>

Deduction of expression type (C++11)

<span>using</span>

Type alias (replaces typedef)

⭐ 3. Storage Class Specifiers

Keyword

Function

<span>auto</span>

(old) Automatic storage duration (now used for type deduction)

<span>register</span>

(deprecated) Suggests placing in a register

<span>static</span>

Static storage duration / Static member of a class

<span>extern</span>

Declares external definition

<span>thread_local</span>

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

<span>inline</span>

Suggests inline function

<span>constexpr</span>

Compile-time constant / function (C++11)

<span>noexcept</span>

Indicates that a function does not throw exceptions (C++11)

<span>virtual</span>

Virtual function, used for polymorphism

<span>override</span>

Explicitly indicates overriding a virtual function (C++11)

<span>final</span>

Prevents further overriding/inheritance (C++11)

<span>return</span>

Return statement

<span>sizeof</span>

Gets the size of a type or object

<span>alignas</span>

Specifies alignment (C++11)

<span>alignof</span>

Gets the alignment requirement of a type (C++11)

<span>typeof</span>

(non-standard, supported by some compilers)

⭐ 5. Access Control and Class-related Keywords

Keyword

Usage

<span>public</span>

Public access

<span>protected</span>

Protected access

<span>private</span>

Private access

<span>friend</span>

Friend function/class, can access private members

<span>class</span>

Defines a class

<span>struct</span>

Defines a structure (default public)

<span>union</span>

Defines a union

<span>enum</span>

Enumeration type

⭐ 6. Templates and Generic Programming

Keyword

Usage

<span>template</span>

Defines a template

<span>typename</span>

Specifies type in a template

<span>requires</span>

Concept constraints (C++20 template constraints)

<span>concept</span>

Defines a concept (C++20)

⭐ 7. Exception Handling

Keyword

Usage

<span>try</span>

Exception catch block

<span>catch</span>

Catches specific exceptions

<span>throw</span>

Throws exceptions

<span>noexcept</span>

Indicates no exceptions thrown (C++11)

⭐ 8. Other and Advanced Features (C++11 and later)

Keyword

Description

<span>nullptr</span>

Null pointer constant (C++11, replaces NULL)

<span>constexpr</span>

Compile-time constant expression/function (C++11)

<span>noexcept</span>

Function does not throw exceptions (C++11)

<span>override</span>

Explicitly indicates overriding a virtual function (C++11)

<span>final</span>

Prevents inheritance/overriding (C++11)

<span>thread_local</span>

Thread-local storage (C++11)

<span>alignas</span>

Specifies alignment (C++11)

<span>alignof</span>

Gets alignment requirement (C++11)

<span>static_assert</span>

Compile-time assertion (C++11)

<span>decltype</span>

Deduction of expression type (C++11)

<span>auto</span>

Type deduction (more powerful since C++11)

<span>using</span>

Type aliasing, template aliasing, namespace introduction, etc.

<span>concept</span>

Template concept (C++20)

<span>requires</span>

Template constraint conditions (C++20)

<span>co_await</span>

Coroutine keyword (C++20 coroutines)

<span>co_yield</span>

Coroutine keyword (C++20 coroutines)

<span>co_return</span>

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>

Leave a Comment