Although
we didn't say so in A
Tutorial Introduction,
there are some restrictions on the names of variables and symbolic constants.
Names are made up of letters and digits; the first character must be a letter.
The underscore ``_''
counts as a letter; it is sometimes useful for improving the readability of
long variable names. Don't begin variable names with underscore, however, since
library routines often use such names. Upper and lower case letters are
distinct, so x and X
are two different names. Traditional C practice is to use lower case for
variable names, and all upper case for symbolic constants.
At
least the first 31 characters of an internal name are significant. For function
names and external variables, the number may be less than 31, because external
names may be used by assemblers and loaders over which the language has no
control. For external names, the standard guarantees uniqueness only for 6
characters and a single case. Keywords like if, else, int, float, etc., are reserved: you can't use
them as variable names. They must be in lower case.
It's
wise to choose variable names that are related to the purpose of the variable,
and that are unlikely to get mixed up typographically. We tend to use short
names for local variables, especially loop indices, and longer names for
external variables.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment