Skip to content
Tutorials Center
My learning

Topics

C++ Reference ยท Keywords and Statements

Reserved words and alternative tokens

Complete list of C++ keywords by category, contextual keywords, alternative tokens (and, or, not), digraphs and reserved identifier rules.

A keyword is a word the language reserves for its own grammar. You cannot use it as the name of a variable, function, type or namespace. C++ also has alternative tokens (and, or, not, ...) that spell operators with words, digraphs that spell punctuation with other punctuation, and a few contextual keywords that are special only in certain positions. Finally, some identifiers that are not keywords are still reserved for the implementation.

This page is a map of all of them. Each keyword has its own reference page where it matters; the table below groups them so you can see what exists.

C++
int class = 1;        // error: 'class' is a keyword
int final = 1;        // fine: 'final' is contextual
bool ok = a and not b;   // alternative tokens for && and !

Try it

C++ Alternative tokens and contextual keywords

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

C++ Digraphs, and what a reserved name looks like

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with std::cin or std::getline), it gets the next line from this box.

Keyword list

Category Keywords
Types bool char char8_t char16_t char32_t wchar_t short int long signed unsigned float double void auto decltype
Type definitions class struct union enum typedef typename using namespace template concept requires
Qualifiers and specifiers const volatile mutable constexpr consteval constinit static extern inline register (removed) thread_local explicit friend virtual noexcept
Control flow if else switch case default for while do break continue goto return try catch throw
Operators (words) new delete sizeof alignof alignas typeid operator this static_cast dynamic_cast const_cast reinterpret_cast
Literals true false nullptr
Other asm static_assert export co_await co_yield co_return import* module*
Contextual (special only in context) override final import module (C++26 adds a few more, such as pre and post for contracts)

The words marked with * are special only at the start of a declaration, as in the first example. Names such as main, std or string are not keywords.

Alternative tokens:

Word Symbol Word Symbol Word Symbol
and && and_eq &= bitand &
or || or_eq |= bitor |
not ! xor_eq ^= xor ^
not_eq != compl ~

Usage notes

  • Alternative tokens are tokens, not macros. and is exactly the same as && to the compiler; you cannot #define and or use and as a variable name. In C they are macros from <iso646.h>, a difference to keep in mind when sharing headers.
  • Digraphs <: :> <% %> %: %:%: map to [ ] { } # ##. Trigraphs (??=) were removed in C++17.
  • Reserved identifiers. Any name with a double underscore, any name starting with an underscore followed by a capital letter, and any name starting with an underscore at global scope is reserved for the compiler and standard library. Using one is undefined behavior (no diagnostic required). Also, do not add your own declarations to namespace std.
  • register was removed in C++17 as a storage-class specifier, but the word stays reserved so you cannot reuse it.
  • Newer words are not reserved retroactively. co_await, concept, requires and consteval became keywords in C++20, so old code that used them as identifiers breaks when moving standards. That is why import and module are contextual.
  • Words from other languages are fine. null, self, string and var are ordinary C++ identifiers.
  • Macros named like keywords (#define private public, a classic test hack) are undefined behavior once standard headers are included.