keywords in c++

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

alignasalignofandand_eqasmautobitandbitor
boolbreakcasecatchcharchar16_tchar32_tclass
complconceptconstconstexprconst_castcontinuedecltypedefault
deletedodoubledynamic_castelseenumexplicitexport
externfalsefloatforfriendgotoifinline
intlongmutablenamespacenewnoexceptnotnot_eq
nullptroperatororor_eqprivateprotectedpublicregister
reinterpret_castrequiresreturnshortsignedsizeofstaticstatic_assert
static_caststructswitchtemplatethisthread_localthrowtrue
trytypedeftypeidtypenameunionunsignedusingvirtual
voidvolatilewchar_twhilexorxor_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.