Identifier Definition: A name associated with a function or data object and used to refer to that function or data object.
An identifier is a name which will be used to describe functions, constants, variables, and other items.
The rules for writing identifiers in C++ are:Identifiers must begin with a letter or underscore.
Only letters(A-Z,a-z), digits(0-9), or underscore( _ ) may follow the initial letter.
Ex: sum_of_squares, box_22A, GetData, count---valid
The blank space cannot be used.
Ex: Get Data cannot be an identifier as blanks are not allowed in identifiers
Identifiers cannot be reserved words. Reserved words or keywords are identifiers reserved for system use.
Ex: int......cannot be an identifier as it is a reserved word in C++
Identifiers beginning with an underscore have special meaning in some C++ systems, so it is best not to start your identtifiers with an underscore.
Most C++ compilers will recognize the first 32 characters in an identifier. Also, C++ is a case sensitive language. C++ will distinguish between upper and lower case letters in identifiers. Therefore:
grade and Grade are different identifiers
A good identifier should also be a mnemonic device which helps describe the nature or purpose of that function or variable. It is better to use grade instead of g, temperature instead of t.
However, avoid excessively long or "cute" identifiers such as:
gradePointAverage or bigHugeUglyNumber
Remember that our goal is to write code which is easy to read and professional in nature.
Programmers will adopt different styles of using upper and lower case letters in writing identifiers. The reserved keywords in C++ must be typed in lower case text, but identifiers can be typed using any combination of upper and lower case letters.
You can develop your own conventions like below:
A single word identifier will be written in lower case only.
Examples: grade, number, sum.
If an identifier is made up of several words, the first letter will be lower case. Subsequent words will begin with upper case.
Some examples are: stringType, passingScore, largestNum.
Identifiers used as constants are often fully capitalized.
Examples: PI, MAXSTRLEN.