C++ Keywords and Identifiers
In this tutorial, we will learn about keywords. Also, we will learn about identifiers, Rules of Identifiers, how to name them, and some good and bad identifiers name in C++ with the help of examples.
1) Keywords are predefined words that have special meanings to the compiler.
2) You can’t use keywords as identidiers as well as variables name in C++ Programs.
3) Keywords are reserved words in C++ liberary and used to perform an internal operations.
For example :-
int is a keyword that indicates dollar is a variable of type integer.
List of Keywords in C++
Here is a list of 32 keywords in C++ language which are also available in C language. (as of C++17)
Here is a list of other keywords in C++ language. (as of C++17)
Note: As C++ is a case sensitive language, all keywords must be written in lowercase.
1) Identifiers are the unique names given to variables, functions, arrays, or other entities by the programmer.
2) Identifiers are the basic requirement of any language.
3) Every language has own rules for naming the identifiers.
Here, dollar and algBly are identifiers.
Rules for naming identifiers
1) Identifiers can be composed of letters, digits, and the underscore character _.
2) It has no limit on name length.
3) It must begin with either a letter or an underscore.
4) Identifier name cannot start with a digit.
5) In C++, uppercase and lowercase letters are distinct. Therefore, Identifiers are case-sensitive.
6) We cannot use keywords as identifiers.
We can choose any name as an identifier if we follow the above rules. However, we should give meaningful names to the identifier that makes sense.
Examples of good and bad identifiers