- Identifiers provide readable names
for variables, functions,
classes, objects, labels,
and defined types.
In C++ identifiers are made up of letters and numbers
within a set of constraints.
These include the 26 letters of the ISO Latin alphabet
in both lowercase and uppercase.
The 10 Western Arabic numerals
and the ASCII underscore character
an identifier may not begin with a numeral.
Identifiers, may not conflict with reserved words,
the current C++ standard reserves 73 keywords
plus 11 alternative tokens.
You cannot use any of these words as an identifier.
Identifiers are case sensitive
capital A lowercase z is different from
lowercase a capital Z.
So even though these both read AZ,
they are different identifiers.
Current standards allow letters
that are not part of the ISO Latin alphabet,
but support for this is implementation dependent
and not portable.
I highly recommend you stick to the 26 letters
of the standard Latin alphabet numbers and the underscore.
If you choose to use non-Latin characters,
you need to be aware that your code may not compile
on other systems, as an example,
this code compiles and runs fine on a Mac with X code
and the client compiler.
It does not compile it all
on Linux with GCC and on Microsoft visual studio,
it compiles with warnings
and runs without displaying
the non-Latin Unicode characters.
Current standards allow identifiers to be of any length,
although only the first 63 characters
are guaranteed to be checked for uniqueness.
And only the first 31 characters
are guaranteed for external identifiers,
so in practice, you should keep your identifiers
under 31 characters long.
An initial underscore character
that is an underscore in the first position of an identifier
is reserved for system identifiers in the global namespace,
it is legal syntax,
but you should avoid identifiers with an initial underscore
in the global namespace.
And we'll talk about scope and namespaces
later in this course.
As with many aspects of programming,
it's a good idea to decide on a consistent style
for choosing identifiers and stick to it.
Understanding the rules,
choosing conventions and sticking with them
will help make your code more readable
and maintainable for the term.