List of 95 keywords in C++ Programming Language

C++ introduction

Popular general-purpose programming language C++ is used a lot in creating software, operating systems, video games, and other things. Because C++ is a compiled language, any code written in it must first be converted into machine code in order to run.

In this article at OpenGenus, we have listed all 95 keywords in C++ Programming Language in a table along with a brief one-line explanation of each keywords.

What are keywords?

Programming language syntax reserves certain terms for specific meanings and uses, known as keywords. They are also used to declare and define variables and data types, as well as to build structures like loops, functions, and conditional expressions.

Total number of keywords in c++ keep on changing depending on the version you are using but overall the number of keywords can be around 90 to 97.

Keywords in C++

Types of keywords in C++:

  1. Control Flow Keywords
  2. Data Type Keywords
  3. Storage Class Keywords
  4. Access Control Keywords
  5. Function Keywords
  6. Object-oriented Keywords
  7. Exception Handling Keywords
  8. Namespace Keywords
  9. Miscellaneous Keywords
Number Keyword Description
1.autoThe auto keyword in C++ enables the compiler to determine a variable's data type from the value that has been assigned to it. When working with complex data types like iterators and lambda functions, this keyword is quite helpful.
2.constIn C++, the unmodifiable status of a variable or function is indicated by the usage of the const keyword. When a variable is specified as const, the programme cannot change its value at any time. Similar to this, a function cannot modify any of the members of its class when it is marked as const.
3.breakWhen using a loop or switch statement, the break keyword in C++ is used to end it. The control of the programme moves to the line of code following the loop or switch statement when the break keyword is used.
4.continueTo go to the next iteration of a loop while skipping the current one, use the continue keyword in C++. The loop skips the remaining statements in the current iteration and begins the subsequent iteration when the continue keyword is encountered.
5.defaultIn switch statements in C++, the default keyword is utilised to offer a default scenario. The programme switches to the default case when none of the cases match the switch expression.
6.doubleWhen declaring a variable in C++ that can hold decimal numbers, the double keyword is used. Greater values can be stored in variables created using the double keyword than in those created with the float keyword.
7.ifIf a given condition is true, use the if statement to describe a block of code that should be executed.
8.intThe int keyword in C++ is used to declare a variable that can store integer values. Variables declared using the int keyword can store values between -2147483648 and 2147483647.
9.returnTo return a value from a function in C++, use the return keyword. When the return keyword is used, the function exits and the calling function takes back control of the programme.
10.switchIn C++, a switch statement is made using the switch keyword. In order to evaluate an expression and execute a block of code based on the value of the expression, switch statements are employed.
11.whileIn C++, a while loop is made with the while keyword. While loops are used to repeatedly run a block of code while a specific condition is true.
12.classIn C++, a new class is created with the class keyword. Data and methods are combined into a single entity using classes. Classes can be used to build objects that can be utilised to access the data and methods contained within the class.
13.virtualIn C++, a virtual function is defined with the virtual keyword. In polymorphism, a subclass can override a method's behaviour that is specified in its superclass by using virtual functions.
14.friendIt used to be possible to define a class or function as a friend of another class, giving it access to the class's protected and private members.
15.inlineThrough the reduction of function call overhead, this is used to advise the compiler to execute inline expansion of a function.
16.typedefThis keyword is used to define data type aliases, which make complex data types simpler for users to understand.
17.mutableThis keyword is used to declare a member variable of a class as modifiable, even if it is declared within a const member function.
18.static_castTo execute explicit type conversions between related data types, use this keyword.
19.tryYou can specify a section of code to be tested for errors as it is being performed using the try statement.
20.volatileThis term is used to denote the possibility that a variable could be changed by outside elements like hardware or other threads.
21.boolA variable with only 2 values possible.
22.privateWhen declaring class members in C++ that may only be accessible from within the class itself, the private keyword is used. This means that functions or objects outside of the class are unable to access private members.
23.protectedThe keyword protected in the C++ language is used to specify the access level of class members. When a class member is marked as protected, the class, any descendant classes, and any friend functions or classes may all access that member. However, code outside of the class hierarchy is unable to access it.
24.publicWhen a class is declared in C++, the word "public" is used to indicate that the members declared following it are available from outside the class.
25.unionA user-defined data type that can hold various types of data in the same memory region is specified by the C++ keyword union. While a union and a structure are similar, they both share the same memory location.
26.typeidTo learn the type information of an object or type, use the C++ keyword typeid. It gives back a pointer to an object called type_info that provides details about the object's type, including its name and if it is a pointer type.
27.voidIn C++, void is a keyword used to indicate that a function does not return any value.
28.deleteMemory that has previously been allocated with the new operator can be deallocated using the C++ keyword delete.
29.reinterpret_castConverts between types by reinterpreting the underlying bit pattern.
30.registerautomatic storage duration. Also hints to the compiler to place the object in the processor's register.
31.usingusing-directives for namespaces and using-declarations for namespace members using-declarations for class members using-enum-declarations for enumerators (since C++20) type alias and alias template declaration (since C++11)
32.typenameA dependent name in a template can be identified as a type using the C++ keyword typename. It is employed in templates that make use of dependent names, or names that rely on a template parameter.
33.static_assertCompile-time assertions are carried out using the C++ keyword static_assert. It is a feature that was added to C++11 and is used to compile-time rather than run-time conditional checking.
34.atomic_commitThe transaction is committed normally even if an exception is raised.
35.co_returnco_return is a new keyword introduced in C++20 to support coroutines, which are a way to suspend and resume the execution of a function at certain points.
36.externIn C++, the extern keyword increases variables' and functions' accessibility across different source files.
37.alignasThe C++ keyword alignas is used to specify a variable or structure's need for alignment. It is used to manage a data structure's memory layout so that the hardware is correctly matched.
38.asmA C++ program's ability to incorporate assembly language source code is provided by asm-declaration.
39.conceptDeclares a named type requirement.
40.noexceptThe noexcept operator performs a compile-time check that returns true if an expression is declared to not throw any exceptions.
41.structThe C++ keyword struct is used to describe a user-defined data type made up of a set of variables.
42.templateWhen defining a generic class or function in C++ that may operate on several sorts of data, the template keyword is utilised.With the use of templates, you are able to establish a general method or data structure without having to identify the specific sorts of data that will be utilised with it.
43.requiresRequires is used to specify requirements on template arguments in a concise way. It is followed by a constraint-expression, which is a boolean expression that specifies the requirements on the template arguments.
44.or_eqThe built-in keyword "or_eq" has existed at least since C++98. It is used mostly for bit manipulation and is an alternative to the |= (Bitwise OR Assignment) operator.
45.nullptrA null pointer value is represented by the term nullptr. To show that an object handle, inner pointer, or native pointer type does not point to an object, provide a null pointer value.
46.signedTo store either negative or positive values, use the signed keyword.
47.xor_eqA substitution for the ^= operator
48.constexprConstant expression is what it signifies. It can also be used with variables, preventing any code from changing the value without raising a compiler error. Contrary to const, constexpr is applicable to functions and class constructors as well. Constexpr denotes a value that is constant and, whenever practical, computed at compile time.
49.co_awaitThe unary operation co_await terminates a coroutine and gives the caller back control.
50.co_yield The co_yield expression suspends the running coroutine while returning a value to the caller.
51.decltypeExamines an entity's declared type or an expression's type and value category.
52.bitorIt is used mostly for bit manipulation and is an alternative to the | (Bitwise OR) operator.
53.alignofIf type-id is a complete object type, an array type with complete elements, or a reference type to one of those types, the function returns the alignment needed in bytes for any instance of that type.
54.andAs an alternative for && (Logical AND operator)
55.explicitIn C++, a constructor is used with the explicit keyword to prevent implicit conversions.
56.importTwo header files are produced by import, which reconstructs the type library's contents in C++ source code.
57.wchar_twhar_t represents the characters that the 'char' type cannot represent can be represented by wide character types.There are many widely used languages and scripts around the world, such as Japanese (Kanji or Hiragana or Katakana), Russian Alphabets, Hindi (Devanagari alphabets), etc.
58.const_castconst_cast makes it possible to form a reference or pointer to non-const type that is actually referring to a const object or a reference or pointer to non-volatile type that is actually referring to a volatile object.
59.newnew expression creates and initializes objects with dynamic storage duration, that is, objects whose lifetime is not necessarily limited by the scope in which they were created.
60.char16_tchar16_t is a fundamental data type that can represent a 16-bit character type.
61.do-whileRepeatedly carries out a statement till the value of expression is false. Each iteration ends with the test.
62.bitandThe C++ keyword bitand is analogous to the operator & and has the same behaviour. Depending on the context, it can take a single or double argument.
63.char32_t32-bit wide characters are represented by the unsigned integer type char32_t.
64.xorThe built-in keyword "xor" has existed at least since C++98. It is used mostly for bit manipulation and is an alternative to the (EXCLUSIVE-OR) operator.
65.thread_localWhen a thread is created, thread_local is defined as a specifier to define the thread-local data, and this data is produced and removed simultaneously.
66.orAn alternative for ||.
67.unsignedA data type specifier known as the unsigned keyword limits a variable's representation to non-negative integer values (positive numbers and zero).
68.moduleAn expression stating that the current translation unit is a module unit.
69.complIt is a substitute for the complement (~) operator and is mostly used to manipulate bits.
70.and_eq An alternative for &=
71.synchronized The C++ attribute synchronise implements functionality for synchronising an object's target method.
72.not As an alternative for ! and to convert true to false or vice-versa.
73.char8_t A character type known as char8_t is used to represent UTF-8 code units.
74.constinint In order for a programme to be valid, a variable must have static initialization, which includes zero initialization and constant initialization.
75.false One of the two values for a bool type variable or a conditional statement is the keyword. False is equal to 0.
76.true One of the two values for a bool type variable or a conditional statement is the keyword.True is equal to 1.
77.else If the same condition is false, use else to describe a block of code that should be executed.
78.throw When a problem is found, the throw keyword throws an exception.
79.catch If an error occurs in the try block, you may specify a block of code to be run by using the catch statement.
80.export The export keyword is designed to make it possible to isolate the definitions from the declarations of C++ templates.
81.reflexpr Through meta-object types, reflexpr gives us access to the object's meta information.
82.this This is a keyword that refers to the current instance of the class.
83.static In C++, the keyword static is used to give special properties to an element. In the static storage area, static items are only ever allotted storage once during the course of a programme. And they are applicable throughout the duration of the programme.
84.case The variable being turned on is tested against the case because the value in the switch is known as a case.
85.char The char keyword is used to declare character type variables.
86.consteval A function or function template is declared as an immediate function via the consteval specifier.
87.enum A user-defined data type called an enumeration is made up of integral constants.
88.dynamic_cast To convert a data from one pointer or reference of a polymorphic type to another, use the dynamic_cast keyword.
89.float The range of numbers that the float type may represent is around 1.5 x 10^-45 to 3.4 x 10^38.
90.forA For loop is a repetition control structure that enables us to create a loop that runs a certain number of times.
91.gotoBy shifting control to another area of the programme, the goto statement can change the way a programme typically runs.
92.longLong is a data type for constants and variables that allows for 64-bit storage of the variable or constant value.
93.not_eqnot_eq is used as an alternative for != .
94.namespaceA namespace is a declarative area that gives the names of the types, functions, variables, etc. within of it a scope.
95.shortA short keyword is used for small integers Range: -32768 to 32767.

Conclusion

To conclude, C++'s keywords play an important role in structure of the language, and any C++ programmer must be familiar with how to use them. Almost all the keywords in C++ are given above, and each keyword has a unique application. C++ programmers can write more effective and efficient code by becoming proficient with these keywords.