Identifiers
Identifiers are the names we give things in our program. These things can be functions
or special locations in memory where data is stored. There are certain rules which must
be followed for identifiers:
Rules for identifiers
-
Must begin with a letter, upper or lower case.
-
May consist of any number of letters or numbers plus the underscore character.
-
May not be any of the reserved words in the C++ language
-
May not contain any spaces
Conventions for Identifiers
The following are not rules for identifiers but they are the conventions that
practically all programmers follow when creating identifiers.
-
An identifier should convey some meaning as to its use. For example,
all of the following identifiers give a fairly clear indication of
what they represent:
CalculateAverage
SumOfSquares
GetNextValue
interestRate
loanValue
numValues
-
Each word in an identifier should start with a capital letter.
Create easy to read identifiers like this: ThisIsAnEasyToReadIdentifier
Not like this: thisisahardtoreadidentifier
-
Some programmers use a lower case letter indicating the data type for variable
names. (s=string, c=char, i=int, l=long, d=double, f=float). For example:
iNumValues
dInterestRate
cFirstLetter
bIsLeapYear
-
You may find other conventions used by programmers in the company where you
eventually get a job.