Tokens in C++: Identifiers
WHAT ARE IDENTIFIERS?
Identifiers are C++ tokens which refer to the names of variables, functions, arrays, classes, objects, etc. These tokens are completely user-specific. As the name suggests, identifiers assist the compiler in 'identifying' the different instances of keywords, such as data-types, classes and functions. The following diagram demonstrates the concept of identifiers in further detail.
As evident from the diagram above, we have a C++ program which uses the capabilities of various predefined and user-defined keywords. Here, int, float, class are predefined keywords, while OwnClass is a user-defined keyword, derived from a pre-existing user-defined class. Now, the program isn't able to utilize the fundamental characteristics of the keywords directly, and thus representatives of these keywords are created in the program. These representatives, shown with dark-green rectangles, are called identifiers.
NOMECLATURE RULES FOR IDENTIFIERS
Though identifiers are free to be user-defined, to ensure compiler sanity and to prevent mis-interpretations, there are few established rules which developers need to follow religiously. These rules are as follows:
- Identifier names cannot start with a numerical digit or a special character.
- A keyword cannot be used as an identifier name.
- In C++, only Alphanumeric (alphabets and numbers) characters and underscore are allowed in identifier names.
- Identifier names are case-sensitive.
Comments
Post a Comment