C++ Keywords: A Comprehensive List and Explanation
C++ is a powerful programming language with a rich set of keywords that form its backbone. These keywords are reserved words that have specific meanings and cannot be used as identifiers (like variable names). Let's delve into a comprehensive list of C++ keywords, grouped by their functionality, and explore their meanings.
C++ Keywords: Basic Types
C++ keywords are categorized into several groups, with the first being basic types. These keywords represent the fundamental data types in C++.
| Keyword | Explanation |
|---|---|
| auto | Automatically deduces the type of a variable based on its initializer. |
| bool | Represents a boolean value (true or false). |
| char | Represents a single character. |
| class | Defines a user-defined data type, providing features like encapsulation, inheritance, and polymorphism. |
| const | Declares a variable whose value cannot be changed. |
| constexpr | Declares a constant or a function whose return value or parameters can be evaluated at compile time. |
| const_cast | Performs a type cast that changes the cv-qualifiers (const or volatile) of an object. |
| double | Represents a double-precision floating-point number. |
| dynamic_cast | Performs a downcast or an upcast at runtime, checking if the cast is safe. |
| enum | Defines a user-defined data type consisting of integral constants. |
| explicit | Prevents implicit conversions that lead to narrow conversions. |
| float | Represents a single-precision floating-point number. |
| int | Represents an integer value. |
| long | Represents a long integer value. |
| short | Represents a short integer value. |
| signed | Specifies that an integer type can represent negative values. |
| sizeof | Returns the size of a type or a variable in bytes. |
| static | Declares a variable with internal linkage, meaning it's only visible within the file it's defined in. |
| struct | Defines a user-defined data type, similar to a class but with default access specifier as public. |
| template | Declares a template, allowing for generic programming. |
| this | Refers to the current object in a member function. |
| typeof | Returns the type of an expression (only available in some compilers). |
| unsigned | Specifies that an integer type cannot represent negative values. |
| void | Represents the absence of a type or the type of a function that doesn't return a value. |
| volatile | Declares a variable that might be modified by external factors, like hardware or the operating system. |
C++ Keywords: Control Flow
The following keywords are used to control the flow of execution in a C++ program.

- break: Terminates the nearest enclosing loop or switch statement.
- case: Specifies a label for a switch statement.
- continue: Skips the current iteration of a loop and moves on to the next one.
- default: Specifies the default case for a switch statement.
- do: Defines a do-while loop, which executes a block of code at least once.
- else: Specifies the block of code to execute if a condition is false.
- for: Defines a for loop, which executes a block of code a specified number of times.
- goto: Transfers control to a labeled statement.
- if: Specifies a conditional statement, which executes a block of code if a condition is true.
- return: Returns a value from a function and terminates its execution.
- switch: Defines a switch statement, which executes different blocks of code based on the value of an expression.
- while: Defines a while loop, which executes a block of code while a condition is true.
C++ Keywords: Functions and Operators
These keywords are related to functions and operators in C++.
- and: Defines a logical AND operation (equivalent to &&).
- and_eq: Defines a logical AND assignment operation (equivalent to &=).
- asm: Declares an inline assembly statement.
- bitand: Defines a bitwise AND operation (equivalent to &).
- bitand_eq: Defines a bitwise AND assignment operation (equivalent to &=).
- bitor: Defines a bitwise OR operation (equivalent to |).
- bitor_eq: Defines a bitwise OR assignment operation (equivalent to |=).
- compl: Defines a bitwise NOT operation (equivalent to ~).
- concept: Declares a concept, which is a predicate that can be used to express requirements on template arguments.
- constexpr: Declares a constant or a function whose return value or parameters can be evaluated at compile time.
- const_cast: Performs a type cast that changes the cv-qualifiers (const or volatile) of an object.
- delete: Defines a delete operator, which frees dynamically allocated memory.
- dynamic_cast: Performs a downcast or an upcast at runtime, checking if the cast is safe.
- explicit: Prevents implicit conversions that lead to narrow conversions.
- export: Declares a module interface, allowing for modular programming.
- friend: Declares a friend function or class, which has access to the private and protected members of another class.
- inline: Declares an inline function, which is expanded in line where it's called.
- module: Defines a module, which is a compilation unit that can be imported by other modules.
- mutable: Declares a member of a const object that can be modified.
- namespace: Defines a scope that prevents name conflicts between different parts of a program.
- new: Defines a new operator, which allocates memory on the heap.
- noexcept: Declares that a function does not throw exceptions.
- not: Defines a logical NOT operation (equivalent to !).
- not_eq: Defines a logical NOT equal to operation (equivalent to !=).
- operator: Defines an operator function, which overloads an operator for a user-defined type.
- or: Defines a logical OR operation (equivalent to ||).
- or_eq: Defines a logical OR assignment operation (equivalent to |=).
- private: Declares the access specifier for members of a class, making them accessible only within the class.
- protected: Declares the access specifier for members of a class, making them accessible within the class and its derived classes.
- public: Declares the access specifier for members of a class, making them accessible from anywhere.
- register: Declares a variable that might be used frequently, hinting to the compiler that it should be stored in a register.
- reinterpret_cast: Performs a type cast that treats one type as if it were another, without performing any conversions.
- static_assert: Declares a static assertion, which checks a condition at compile time and generates an error if the condition is false.
- template: Declares a template, allowing for generic programming.
- this: Refers to the current object in a member function.
- throw: Declares that a function might throw an exception.
- typeof: Returns the type of an expression (only available in some compilers).
- typename: Declares a type name, which can be used to resolve ambiguities in template declarations.
- using: Declares a using directive or declaration, which brings names from a namespace into the current scope.
- virtual: Declares a virtual function, which can be overridden by derived classes.
- wchar_t: Represents a wide character.
C++ Keywords: Preprocessor Directives
The following keywords are used as preprocessor directives, which are processed by the preprocessor before compilation.
- #define: Defines a macro, which is a symbolic constant or a function.
- #if: Conditionally includes or excludes a section of code based on a condition.
- #ifdef: Conditionally includes or excludes a section of code if a macro is defined.
- #ifndef: Conditionally includes or excludes a section of code if a macro is not defined.
- #include: Includes a header file in the current source file.
- #undef: Undefines a macro, removing its definition.
Understanding C++ keywords is crucial for any developer working with the language. This list should serve as a comprehensive reference for both beginners and experienced developers alike. Happy coding!
























