Language Reference Complete List
Reserved Words

C++ Keywords: Complete Reference Guide

Comprehensive alphabetical list of all 95 C++ keywords with detailed descriptions, usage 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

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

Basic Control Flow Keywords
// if, else, for, while, break, continue
#include 
using namespace std;

int main() {
    // if-else statement
    int x = 10;
    if (x > 5) {
        cout << "x is greater than 5" << endl;
    } else {
        cout << "x is 5 or less" << endl;
    }
    
    // for loop with break and continue
    for (int i = 0; i < 10; i++) {
        if (i == 2) {
            continue; // Skip iteration when i is 2
        }
        if (i == 8) {
            break; // Exit loop when i is 8
        }
        cout << i << " ";
    }
    
    // while loop
    int count = 0;
    while (count < 5) {
        cout << "Count: " << count << endl;
        count++;
    }
    
    return 0;
}
Modern C++ Keywords (C++11 and later)
// auto, nullptr, constexpr, noexcept, decltype
#include 
#include 
using namespace std;

// constexpr function (compile-time computation)
constexpr int factorial(int n) {
    return (n <= 1) ? 1 : n * factorial(n - 1);
}

// noexcept function (no exception guarantee)
void safe_function() noexcept {
    cout << "This function won't throw exceptions" << endl;
}

int main() {
    // auto type deduction
    auto x = 42;           // x is int
    auto y = 3.14;         // y is double
    auto z = "hello";      // z is const char*
    
    // nullptr instead of NULL
    int* ptr = nullptr;
    if (ptr == nullptr) {
        cout << "Pointer is null" << endl;
    }
    
    // constexpr variable (compile-time constant)
    constexpr int max_size = factorial(5); // Computed at compile-time
    cout << "Max size: " << max_size << endl;
    
    // decltype - get type from expression
    int a = 10;
    decltype(a) b = 20; // b is int
    cout << "Type of b: " << typeid(b).name() << endl;
    
    return 0;
}

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.