C++ identifiers are the name assigned to a function, variable, or any other user-defined item. They are the basic requirement of any language. Identifiers can be from one to several characters long.
In short, we can say that the C++ identifiers represent the essential elements in a program which are given below:
Some naming rules are common in both C and C++. They are as follows:
Below are some guidelines for working with identifiers
When creating your own style spelling and capitalization should not be overlooked .
Below are some tips for these areas include the following.
enum TextStyle { tsPlain, tsBold, tsItalic, tsUnderscore, };
The following are the examples of valid identifiers are:
Result Test2 _sum power
The following are the examples of invalid identifiers.
Sum-1 // containing special character '-'. 2data // the first letter is a digit. break // use of a keyword.
Below table shows the valid and invalid identifiers.
Valid | Invalid |
---|---|
Count | 1count |
test23 | hi!there |
high_balance | high...balance |
The major difference between C and C++ is the limit on the length of the name of the variable. ANSI C considers only the first 32 characters in a name while ANSI C++ imposes no limit on the length of the name.
The following is the list of differences between identifiers and keywords.
Identifiers | Keywords |
---|---|
Identifiers are the names defined by the programmer to the basic elements of a program. | Keywords are the reserved words whose meaning is known by the compiler. |
It is used to identify the name of the variable. | It is used to specify the type of entity. |
It can consist of letters, digits, and underscore. | It contains only letters. |
It can use both lowercase and uppercase letters. | It uses only lowercase letters. |
No special character can be used except the underscore. | It cannot contain any special character. |
The starting letter of identifiers can be lowercase, uppercase or underscore. | It can be started only with the lowercase letter. |
It can be classified as internal and external identifiers. | It cannot be further classified. |
Examples: test, result, sum, power, etc. | Examples: 'for', 'if', 'else', 'break', etc. |