Language Reference Complete List
Reserved Words

C++ Keywords: Complete Reference Guide

Comprehensive alphabetical list of all 95 C++ keywords with detailed descriptions, short focused examples, and importance ratings. Essential reference for C++ programmers.

95 Keywords

Total reserved words

Reserved

Cannot be used as identifiers

C++11/14/17/20

Modern C++ additions

Examples

Practical usage samples

C++ Tutorial · C++ Keywords

Keywords are reserved tokens with special meaning for the compiler. Knowing them helps you read errors, avoid illegal names, and understand control flow and OOP syntax.

C++ keywords infographic: reserved words list, data type keywords, control flow keywords, OOP keywords, and identifier rules
C++ keywords reference — reserved words you cannot use as identifiers, grouped by purpose for syntax and interview study.

What you will learn

  • Identify core keywords for types, control flow, and classes
  • Distinguish C++-only keywords from C heritage
  • Avoid using keywords as variable names
  • Recognize context-specific keywords (override, final)
  • Connect keywords to upcoming OOP and template topics

Why this topic matters

Interviewers ask about static, virtual, explicit, and friend. Keyword fluency signals you read code professionally, not just tutorials.

Key terms & indexing

C++ keywords reserved words C++ C++ identifiers C++ syntax

Understanding C++ Keywords

Keywords (also called reserved words) are predefined identifiers that have special meaning in C++. They cannot be used as variable names, function names, or any other identifiers. C++ has 95 keywords as of C++20 standard.

Key Points:
  • Keywords are case-sensitive (all lowercase in C++)
  • They define the language's syntax and structure
  • New keywords are added in each C++ standard
  • Using keywords as identifiers causes compilation errors
Critical Keywords

Essential for basic program structure: int, if, for, class

Type Keywords

Define data types: char, double, bool, auto

OOP Keywords

Object-oriented features: public, private, virtual, friend

Modern C++

C++11 and later: constexpr, noexcept, decltype, thread_local

Quick Alphabetical Index

A B C D E F G H I L M N O P R S T U V W X Y

Complete C++ Keywords Reference

The following table lists all C++ keywords alphabetically with descriptions and importance ratings:

Keyword Description / Purpose Usage Example Importance Level
A
alignas Specifies alignment requirement for types and objects (C++11) alignas(16) int x; Medium Advanced memory alignment
alignof Queries alignment requirement of a type (C++11) alignof(int) Medium Low-level programming
asm Inline assembly code insertion asm("nop"); Low Platform-specific
auto Automatic type deduction (C++11: type inference) auto x = 42; High Modern C++ essential
B
bool Boolean data type (true/false) bool flag = true; Critical Fundamental type
break Exit from a loop or switch statement break; Critical Flow control
C
case Label in switch statement case 1: break; High Switch statements
catch Exception handling block catch(Exception& e) {} High Error handling
char Character data type (1 byte) char c = 'A'; Critical Fundamental type
char8_t UTF-8 character type (C++20) char8_t c = u8'a'; Medium Unicode support
class Defines a class (user-defined type) class MyClass {}; Critical OOP fundamental
const Declares constant values or functions const int MAX = 100; Critical Immutability
consteval Immediate function (C++20) consteval int sqr(int n) {} Medium Compile-time execution
constexpr Constant expression (C++11) constexpr int size = 10; High Compile-time computation
const_cast Removes const/volatile qualifiers const_cast(x) Medium Type casting
continue Skips to next iteration of loop continue; High Flow control
D
decltype Declares type from expression (C++11) decltype(x) y = x; High Type inference
default Default case in switch or default function default: break; High Switch/default functions
delete Deallocates dynamic memory delete ptr; Critical Memory management
do Do-while loop construct do { } while(cond); High Loop structure
double Double-precision floating point type double pi = 3.14159; Critical Fundamental type
dynamic_cast Safe downcasting in inheritance hierarchy dynamic_cast(base) High Polymorphic casting
E
else Alternative in if-else statement else { } Critical Conditional logic
enum Declares enumeration type enum Color {RED, GREEN}; High Named constants
explicit Prevents implicit conversions explicit MyClass(int); High Constructor control
export Template declaration (C++20 modules) export template Medium Modules feature
extern External linkage declaration extern int globalVar; High Linkage specification
F
false Boolean false literal bool flag = false; Critical Boolean logic
float Single-precision floating point type float f = 3.14f; Critical Fundamental type
for For loop construct for(int i=0; i<10; i++) {} Critical Loop structure
friend Grants access to private/protected members friend class FriendClass; High Access control
I
if Conditional statement if(condition) { } Critical Fundamental control flow
inline Hint to compiler for function inlining inline void func() {} High Performance optimization
int Integer data type int number = 42; Critical Most fundamental type
N
namespace Declares a scope for identifiers namespace MyNS { } High Organization & avoiding conflicts
new Allocates dynamic memory int* p = new int; Critical Memory management
noexcept Specifies function won't throw exceptions (C++11) void func() noexcept {} High Exception specification
nullptr Null pointer literal (C++11) int* ptr = nullptr; Critical Null pointer representation
P
private Private access specifier in classes private: int x; Critical Encapsulation
protected Protected access specifier in classes protected: void func(); Critical Inheritance
public Public access specifier in classes public: MyClass(); Critical Interface definition
R
return Returns from a function with optional value return 42; Critical Function control
S
short Short integer type short s = 100; High Integer type
signed Signed integer modifier signed int x; High Integer sign specification
sizeof Returns size of type or object in bytes sizeof(int) Critical Memory size query
static Static storage duration or class member static int count; Critical Storage duration control
static_assert Compile-time assertion (C++11) static_assert(sizeof(int)==4); High Compile-time checking
static_cast Compile-time type conversion static_cast(x) Critical Type conversion
struct Defines a structure (class with public default) struct Point {int x,y;}; Critical Data aggregation
switch Multi-way conditional statement switch(value) {} Critical Multi-way branching
T
template Generic programming declaration template Critical Generic programming
this Pointer to current object instance this->member = value; Critical Object self-reference
thread_local Thread-local storage (C++11) thread_local int tls_var; Medium Multithreading
throw Throws an exception throw runtime_error("msg"); High Exception handling
true Boolean true literal bool flag = true; Critical Boolean logic
try Exception handling block try { } catch(...) {} High Exception handling
typedef Creates type alias (legacy, use using in C++11) typedef int Integer; High Type aliasing
typeid Runtime type information query typeid(variable).name() Medium RTTI
typename Specifies a type in templates typename T::value_type High Template programming
U
union Defines a union (shared memory for types) union Data {int i; float f;}; Medium Memory optimization
unsigned Unsigned integer modifier unsigned int x; Critical Integer sign specification
using Type alias or using declaration (C++11) using Integer = int; High Modern type aliasing
V
virtual Declares virtual function for polymorphism virtual void draw() = 0; Critical Polymorphism
void Absence of type (functions, pointers) void func(); void* ptr; Critical Type specification
volatile Prevents compiler optimization (hardware access) volatile int* reg; Medium Low-level programming
W
wchar_t Wide character type wchar_t wc = L'A'; High Unicode support
while While loop construct while(condition) {} Critical Loop structure
Quick Statistics:

Total Keywords: 95

C++11 Added: 10+

C++20 Added: 5+

Critical Importance: 40+

Keyword Usage Examples

Fundamental Keywords in Action

Simple Examples

1. if keyword
int x = 10;
if (x > 5)
    cout << "Greater";
2. else keyword
int n = 3;
if (n % 2 == 0)
    cout << "Even";
else
    cout << "Odd";
3. for loop
for (int i = 0; i < 5; i++)
    cout << i << " ";
4. while loop
int c = 0;
while (c < 3) {
    cout << c++;
}
5. break
for (int i = 0; i < 10; i++) {
    if (i == 5) break;
}
6. continue
for (int i = 0; i < 5; i++) {
    if (i == 2) continue;
    cout << i;
}

Modern C++ Keywords (C++11+)

Simple Examples

1. auto deduction
auto x = 42;      // int
auto y = 3.14;    // double
2. nullptr
int* p = nullptr;
if (p == nullptr)
    cout << "Null";
3. constexpr var
constexpr int N = 10;
int arr[N]; // size at compile-time
4. decltype
int a = 10;
decltype(a) b = 20;
5. noexcept
void safe() noexcept {
    cout << "No throw";
}
6. return keyword
int add(int a, int b) {
    return a + b;
}

Importance Levels & Best Practices

Critical Importance

Fundamental keywords used in almost every C++ program:

  • Data Types: int, char, bool, float, double
  • Control Flow: if, else, for, while, switch
  • OOP: class, public, private, virtual
  • Memory: new, delete, sizeof
High Importance

Frequently used keywords for intermediate/advanced programming:

  • Templates: template, typename
  • Modern C++: auto, nullptr, constexpr
  • Exceptions: try, catch, throw
  • Access: friend, explicit
Common Mistakes to Avoid
  • Don't use keywords as identifiers: int class = 5;
  • Remember case sensitivity: Class is not a keyword, class is
  • Use modern alternatives: Prefer nullptr over NULL, using over typedef
  • Be careful with goto: Avoid using goto - it leads to spaghetti code

Summary & Quick Reference

Learning Path
  • Beginner: Master 20-30 core keywords (int, if, for, class, etc.)
  • Intermediate: Learn OOP and template keywords (virtual, template, typename)
  • Advanced: Study modern C++ keywords (auto, constexpr, noexcept)
  • Expert: Understand all 95 keywords including rarely used ones (asm, goto)
Most Used Keywords
int if for class void return const auto template namespace

Final Notes

C++ keywords form the foundation of the language. While you don't need to memorize all 95 keywords immediately, understanding the core ones is essential. Modern C++ (C++11/14/17/20) has introduced powerful new keywords that make programming safer and more efficient. Always refer to the official C++ standard documentation for the most up-to-date keyword list.

Frequently asked questions

How many keywords does C++ have?

The set grows with standards (C++11/14/17/20). Focus on common ones: int, class, virtual, template, namespace, etc.

Can I use 'class' as a variable name?

No—keywords cannot be identifiers. The compiler will report a syntax error.

What does the static keyword mean?

Depends on context: static storage duration, class members, or internal linkage at file scope.