C++ Keywords

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Keywords have fixed meaning defined by the C++ standard and cannot be used as identifiers. It is illegal to redefine keywords using the preprocessor in any translation unit that includes a standard library header. However, keywords lose their special meaning inside attributes.

Syntax

  • asm (string-literal);
  • noexcept(expression) // meaning 1
  • noexcept(constant-expression) // meaning 2
  • noexcept // meaning 2
  • sizeof unary-expression
  • sizeof(type-id)
  • sizeof...(identifier) // since C++11
  • typename nested-name-specifier identifier // meaning 1
  • typename nested-name-specifier template(opt) simple-template-id // meaning 1
  • typename identifier(opt) // meaning 2
  • typename... identifier(opt) // meaning 2; since C++11
  • typename identifier(opt) = type-id // meaning 2
  • template <template-parameter-list> typename ...(opt) identifier(opt) // meaning 3
  • template <template-parameter-list> typename identifier(opt) = id-expression // meaning 3

Remarks

The full list of keywords is as follows:

The tokens final and override are not keywords. They may be used as identifiers and have special meaning only in certain contexts.

The tokens and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, and xor_eq are alternative spellings of &&, &=, &, |, ~, !, !=, ||, |=, ^, and ^=, respectively. The standard does not treat them as keywords, but they are keywords for all intents and purposes, since it is impossible to redefine them or use them to mean anything other than the operators they represent.

The following topics contain detailed explanations of many of the keywords in C++, which serve fundamental purposes such as naming basic types or controlling the flow of execution.



Got any C++ Question?