C++ Keywords
Keywords are the reserved words that have special meanings in the C++ language. They are the words that the language uses for a specifying the components of the language, such as void, int, public, etc. They can’t be used for a variable name or function name or any other identifiers.
Let’s take a look at the hello world code:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World";
return 0;
}
Output
Hello World
Explanation: In the above code, using, namespace, and return are the keywords that are used to implement some functionality of the language. Their meaning is predefined in C++ and will always remain same.
The total number of keywords in C++ are 95 upto C++ 23 specification. Below is the table for all C++ keywords:
| alignas | alignof | and | and_eq | asm |
| auto | bitand | bitor | bool | break |
| case | catch | char | char8_t | char16_t |
| char32_t | class | compl | concept | const |
| consteval | constexpr | constinit | const_cast | continue |
| co_await | co_return | co_yield | decltype | default |
| delete | do | double | dynamic_cast | else |
| enum | explicit | export | extern | false |
| final | float | for | friend | goto |
| if | inline | int | long | mutable |
| namespace | new | noexcept | not | not_eq |
| nullptr | operator | or | or_eq | private |
| protected | public | register | reinterpret_cast | requires |
| return | short | signed | sizeof | static |
| static_assert | static_cast | struct | switch | template |
| this | thread_local | throw | true | try |
| typedef | typeid | typename | union | unsigned |
| using | virtual | void | volatile | wchar_t |
| while | xor | xor_eq |
Keywords vs Identifiers
So, there are some properties of keywords that distinguish keywords from identifiers. They listed in the below table
| Keywords | Identifiers |
|---|---|
| Keywords are predefined/reserved words | identifiers are the values used to define different programming items like a variable, integers, structures, and unions. |
| It defines the type of entity. | It classifies the name of the entity. |
| A keyword contains only alphabetical characters, | an identifier can consist of alphabetical characters, digits, and underscores. |
| It should be lowercase. | It can be both upper and lowercase. |
| No special symbols or punctuations are used in keywords and identifiers. | No special symbols or punctuations are used in keywords and identifiers. The only underscore can be used in an identifier. |
| Example: int, char, while, do. | Example: Geeks_for_Geeks, GFG, Gfg1. |


