When you’re starting with C++, one of the most fundamental things you need to understand is keywords. These are the reserved words that the language uses to perform specific tasks. Knowing them well is essential to writing clean, bug-free, and understandable code.
what is keyword in c++
A keyword in C++ is a reserved word that has a predefined meaning in the language. These words are part of the C++ syntax and cannot be used as identifiers (like variable names, function names, etc.).
They form the core building blocks of your programs — controlling logic, declaring types, managing flow, and more.
For example:
int number = 10; // 'int' is a keyword
if (number > 5) { // 'if' is a keyword
// do something
}
list of c++ keywords
alignas | alignof | and | and_eq | asm | auto | bitand | bitor |
---|---|---|---|---|---|---|---|
bool | break | case | catch | char | char16_t | char32_t | class |
compl | concept | const | constexpr | const_cast | continue | decltype | default |
delete | do | double | dynamic_cast | else | enum | explicit | export |
extern | false | float | for | friend | goto | if | inline |
int | long | mutable | namespace | new | noexcept | not | not_eq |
nullptr | operator | or | or_eq | private | protected | public | register |
reinterpret_cast | requires | return | short | signed | sizeof | static | static_assert |
static_cast | struct | switch | template | this | thread_local | throw | true |
try | typedef | typeid | typename | union | unsigned | using | virtual |
void | volatile | wchar_t | while | xor | xor_eq |
Categories of C++ Keywords
Let’s break the keywords into meaningful groups:
1. Data Types
int
, char
, float
, double
, bool
, void
, wchar_t
, char16_t
, char32_t
2. Control Flow
if
, else
, switch
, case
, default
, while
, do
, for
, break
, continue
, goto
, return
3. Modifiers
signed
, unsigned
, short
, long
, const
, static
, mutable
, volatile
, extern
, register
, inline
, thread_local
4. Object-Oriented Keywords
class
, struct
, private
, public
, protected
, friend
, this
, virtual
, new
, delete
5. Type Conversions and Casting
const_cast
, static_cast
, dynamic_cast
, reinterpret_cast
6. Exception Handling
try
, catch
, throw
7. Operator Overloading
operator
, explicit
8. Namespace and Scope
namespace
, using
, typename
, typeid
, decltype
9. Boolean Logic
true
, false
, not
, and
, or
, xor
, not_eq
, and_eq
, or_eq
, xor_eq
, bitand
, bitor
, compl
10. Others / Advanced
auto
, constexpr
, noexcept
, static_assert
, alignas
, alignof
, asm
, export
, concept
, requires
Frequently Asked Questions (FAQs)
1. Can I use C++ keywords as variable names?
No, C++ keywords are reserved by the language and cannot be used as identifiers (like variable names, class names, or function names). Doing so will result in a compilation error.
2. Are C++ keywords case-sensitive?
Yes, C++ is a case-sensitive language. So int
is a valid keyword, but Int
, INT
, or iNt
are not recognized as the keyword int
.
3. Do newer versions of C++ add new keywords?
Yes. Each new version of the C++ standard may introduce new keywords. For example, constexpr
, noexcept
, and nullptr
were added in C++11, while concept
and requires
came in C++20.
4. What happens if I accidentally use a keyword as a variable name?
The compiler will throw an error. For example:
int for = 5; // Error: 'for' is a reserved keyword
5. Is there a way to list all keywords supported by my compiler?
Yes, most compilers and IDEs provide documentation listing supported keywords. You can also refer to the official C++ standard documentation or use help
commands if your IDE/compiler supports it.