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++:
- Control Flow Keywords
- Data Type Keywords
- Storage Class Keywords
- Access Control Keywords
- Function Keywords
- Object-oriented Keywords
- Exception Handling Keywords
- Namespace Keywords
- Miscellaneous Keywords
|The 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.
|In 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.
|When 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.
|To 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.
|In 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.
|When 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.
|If a given condition is true, use the if statement to describe a block of code that should be executed.
|The 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.
|To 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.
|In 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.
|In 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.
|In 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.
|In 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.
|It 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.
|Through the reduction of function call overhead, this is used to advise the compiler to execute inline expansion of a function.
|This keyword is used to define data type aliases, which make complex data types simpler for users to understand.
|This keyword is used to declare a member variable of a class as modifiable, even if it is declared within a const member function.
|To execute explicit type conversions between related data types, use this keyword.
|You can specify a section of code to be tested for errors as it is being performed using the try statement.
|This term is used to denote the possibility that a variable could be changed by outside elements like hardware or other threads.
|A variable with only 2 values possible.
|When 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.
|The 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.
|When 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.
|A 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.
|To 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.
|In C++, void is a keyword used to indicate that a function does not return any value.
|Memory that has previously been allocated with the new operator can be deallocated using the C++ keyword delete.
|Converts between types by reinterpreting the underlying bit pattern.
|automatic storage duration. Also hints to the compiler to place the object in the processor's register.
|using-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)
|A 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.
|Compile-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.
|The transaction is committed normally even if an exception is raised.
|co_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.
|In C++, the extern keyword increases variables' and functions' accessibility across different source files.
|The 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.
|A C++ program's ability to incorporate assembly language source code is provided by asm-declaration.
|Declares a named type requirement.
|The noexcept operator performs a compile-time check that returns true if an expression is declared to not throw any exceptions.
|The C++ keyword struct is used to describe a user-defined data type made up of a set of variables.
|When 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.
|Requires 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.
|The 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.
|A 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.
|To store either negative or positive values, use the signed keyword.
|A substitution for the ^= operator
|Constant 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.
|The unary operation co_await terminates a coroutine and gives the caller back control.
|The co_yield expression suspends the running coroutine while returning a value to the caller.
|Examines an entity's declared type or an expression's type and value category.
|It is used mostly for bit manipulation and is an alternative to the | (Bitwise OR) operator.
|If 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.
|As an alternative for && (Logical AND operator)
|In C++, a constructor is used with the explicit keyword to prevent implicit conversions.
|Two header files are produced by import, which reconstructs the type library's contents in C++ source code.
|whar_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.
|const_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.
|new 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.
|char16_t is a fundamental data type that can represent a 16-bit character type.
|Repeatedly carries out a statement till the value of expression is false. Each iteration ends with the test.
|The 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.
|32-bit wide characters are represented by the unsigned integer type char32_t.
|The 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.
|When 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.
|An alternative for ||.
|A data type specifier known as the unsigned keyword limits a variable's representation to non-negative integer values (positive numbers and zero).
|An expression stating that the current translation unit is a module unit.
|It is a substitute for the complement (~) operator and is mostly used to manipulate bits.
|An alternative for &=
|The C++ attribute synchronise implements functionality for synchronising an object's target method.
|As an alternative for ! and to convert true to false or vice-versa.
|A character type known as char8_t is used to represent UTF-8 code units.
|In order for a programme to be valid, a variable must have static initialization, which includes zero initialization and constant initialization.
|One of the two values for a bool type variable or a conditional statement is the keyword. False is equal to 0.
|One of the two values for a bool type variable or a conditional statement is the keyword.True is equal to 1.
|If the same condition is false, use else to describe a block of code that should be executed.
|When a problem is found, the throw keyword throws an exception.
|If an error occurs in the try block, you may specify a block of code to be run by using the catch statement.
|The export keyword is designed to make it possible to isolate the definitions from the declarations of C++ templates.
|Through meta-object types, reflexpr gives us access to the object's meta information.
|This is a keyword that refers to the current instance of the class.
|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.
|The variable being turned on is tested against the case because the value in the switch is known as a case.
|The char keyword is used to declare character type variables.
|A function or function template is declared as an immediate function via the consteval specifier.
|A user-defined data type called an enumeration is made up of integral constants.
|To convert a data from one pointer or reference of a polymorphic type to another, use the dynamic_cast keyword.
|The range of numbers that the float type may represent is around 1.5 x 10^-45 to 3.4 x 10^38.
|A For loop is a repetition control structure that enables us to create a loop that runs a certain number of times.
|By shifting control to another area of the programme, the goto statement can change the way a programme typically runs.
|Long is a data type for constants and variables that allows for 64-bit storage of the variable or constant value.
|not_eq is used as an alternative for != .
|A namespace is a declarative area that gives the names of the types, functions, variables, etc. within of it a scope.
|A short keyword is used for small integers Range: -32768 to 32767.
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.