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.
Comprehensive alphabetical list of all 95 C++ keywords with detailed descriptions, short focused examples, and importance ratings. Essential reference for C++ programmers.
Total reserved words
Cannot be used as identifiers
Modern C++ additions
Practical usage samples
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.
Interviewers ask about static, virtual, explicit, and friend. Keyword fluency signals you read code professionally, not just tutorials.
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.
Essential for basic program structure: int, if, for, class
Define data types: char, double, bool, auto
Object-oriented features: public, private, virtual, friend
C++11 and later: constexpr, noexcept, decltype, thread_local
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 |
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 |
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 |
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 |
Total Keywords: 95
C++11 Added: 10+
C++20 Added: 5+
Critical Importance: 40+
int x = 10;
if (x > 5)
cout << "Greater";int n = 3;
if (n % 2 == 0)
cout << "Even";
else
cout << "Odd";for (int i = 0; i < 5; i++)
cout << i << " ";int c = 0;
while (c < 3) {
cout << c++;
}for (int i = 0; i < 10; i++) {
if (i == 5) break;
}for (int i = 0; i < 5; i++) {
if (i == 2) continue;
cout << i;
}auto x = 42; // int
auto y = 3.14; // doubleint* p = nullptr;
if (p == nullptr)
cout << "Null";constexpr int N = 10;
int arr[N]; // size at compile-timeint a = 10;
decltype(a) b = 20;void safe() noexcept {
cout << "No throw";
}int add(int a, int b) {
return a + b;
}Fundamental keywords used in almost every C++ program:
Frequently used keywords for intermediate/advanced programming:
int class = 5; ❌Class is not a keyword, class isnullptr over NULL, using over typedefgoto - it leads to spaghetti codeC++ 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.
The set grows with standards (C++11/14/17/20). Focus on common ones: int, class, virtual, template, namespace, etc.
No—keywords cannot be identifiers. The compiler will report a syntax error.
Depends on context: static storage duration, class members, or internal linkage at file scope.