Before discussing keywords and identifiers, we should actually know what makes a C++ program. So, the basic building blocks of a program are called Tokens.
Tokens:
Tokens are the smallest entity or individual units of the C++ language. A C++ program is made up of a combination of small tokens just like cells of our body or bricks of a building. Tokens are different by nature and purpose, that is why they are classified into 6 types:
- Keywords
- Identifiers
- Constants
- Special symbols
- Operators
- Strings

Keywords:
The keyword is a reserved word whose meaning or definition is already known or predefined (as you can say) to the compiler. It is reserved because it needs to serve a specific purpose, it is made or developed to do that task only. Keywords have some rules which should be followed while using them. So, the rules to remember while inserting keywords in a program are:
- As it is reserved so, it’s meaning cannot be changed to use for other purposes which it is not meant to do.
- Keywords cannot be used for giving names to use defined things in the program like class, object etc.
- Keywords are always written in lower cases.
Here is a list of all C++ keywords. (as of C++17)
alignas | decltype | namespace | struct |
alignof | default | new | switch |
and | delete | noexcept | template |
and_eq | do | not | this |
asm | double | not_eq | thread_local |
auto | dynamic_cast | nullptr | throw |
bitand | else | operator | true |
bitor | enum | or | try |
bool | explicit | or_eq | typedef |
break | export | private | typeid |
case | extern | protected | typename |
catch | false | public | union |
char | float | register | unsigned |
char16_t | for | reinterpret_cast | using |
char32_t | friend | return | virtual |
class | goto | short | void |
compl | if | signed | volatile |
const | inline | sizeof | wchar_t |
constexpr | int | static | while |
const_cast | long | static_assert | xor |
continue | mutable | static_cast | xor_eq |
Identifiers:
Identifiers are used to give names to user-defined (defined by users, whose meaning is not known to the compiler) things like class, object, variables, constants, array, functions. Identifiers also have rules to apply just like keywords have but the rules are different.
So, rules to use identifiers in a program are:
- They consist of alphabets[(A-Z) and(a-z)], digits (0 to 9), _(underscore).
- Identifiers should not start with digits. For example: ‘5_web’ cannot be used as an identifier.
- Identifiers are case sensitive which means upper case letters are treated differently from lower case letters. For example, min and MIN are two different identifiers.
- No special symbols other than underscore can be used in identifiers and there should not be any blank spaces either.
- Keywords cannot be used as identifiers. For example, we can’t use while as an identifier like ‘int while’.
Constants:
The Constant refers to fixed values that cannot be changed during the execution of the program, unlike variables that can be changed.
Special Symbols:
These are the symbols that are used for specific purposes and cannot be used for other tasks. These symbols are brackets [], parentheses (), braces {}, comma (,), colon (:), asterisk (*), semi-colon (;), pre-processor (#) and assignment operator (=).
Spaces and Syntax:
These are blank spaces that are used in a program.
Quick Recap: We discussed tokens, types of tokens, Keywords, rules for Keywords, identifiers. Rules for identifiers and some other tokens. We didn’t discuss briefly operators, special symbols, strings and constants as it’s not the topic of the article but we will know about them in another article briefly. Thank you.
Difference between Keyword and Identifier:
SR. NO. | KEYWORD | IDENTIFIER |
---|---|---|
1 | Keywords are reserved words and can’t be changed. In C/C++, keywords are special meaning and used in programming. | Identifiers are used to define inside programming languages like a declaration of variables, data types and mostly alphabetic characters. |
2 | Keywords are a specific type or kind of entity. | An identifier is the identity of a particular entity. |
3 | Keywords are always started with lower case letters. | According to Identifier first character can be uppercase, lowercase or underscore. |
4 | Always keep remembered keyword should be in lower case. | An identifier in variable declaration accepts underscore or upper case or lower case. |
5 | Keywords always contain alphabetic characters. | An identifier in data types always in lower case. |
6 | They help to build a specific instruction that exists within the computer programming language. | The identifier can be any unique name that can be used to identify the variable. |
7 | In Keywords, no special symbols and punctuations are used. | No punctuation or special symbol except ‘underscore’ is used. |
8 | Keywords examples are int, char, if, while, do, class etc. | type identifier: Here type means is the keyword that represents the data type, for example, int, float, boolean, string etc. |
Please write comments or WhatsApp if you find anything incorrect, or you want to share more information about the topic discussed above.