Loading...
C++ Keywords and Identifiers

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.


Keywords

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 dollar;

Here, 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)

Swipe right to see more
asm dynamic_cast namespace reinterpret_cast bool
explicit new static_cast false catch
operator template friend private class
this inline public throw const_cast
delete mutable protected true try
typeid typename using virtual wchar_t

Here is a list of other keywords in C++ language. (as of C++17)

Swipe right to see more
alignas decltype and noexcept alignof
template and_eq not not_eq thread_local
nullptr bitand bitor enum or
or_eq typedef export char16_t char32_t
compl volatile constexpr static_assert xor
xor_eq

Note: As C++ is a case sensitive language, all keywords must be written in lowercase.


C++ Identifiers

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.

For example,

int dollar;
double algBly;

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

Invalid Identifier Bad Identifier Good Identifier
Points table P_table pointsTable
1apple apple_1 apple1
int n_int intNumber

Next Tutorial

We hope that this tutorial helped you develop better understanding of the concept of Keywords & Identifiers in C++.

Keep Learning : )

In the next tutorial, you'll learn about C++ Data Types.

- Related Topics