Tuesday 11 September 2012

C++ ( Tutorials X )

1.) Identifiers:-

Identifiers are very important in C++ and are used in all programs. What is an identifier?In the previous program ‘check’ was declared as a character variable. The identifier in this case is ‘check’. Basically identifiers are names that are given to variables, constants or functions. In the previous program there are two identifiers: ‘check’ and ‘i’. 


C++ permits the use of a huge variety of names for identifiers like:

test, Test, int_test, var1, var123, c_b_f, _var

Almost any name you can think of can be used as an identifier but there are some restrictions. An identifier should not start with a number. The first character of an identifier should be an alphabet or an underscore ( _ ).
After the first character, numbers can be used in the identifier. Remember the following:

a.) Never start an identifier with anything other than a letter or an underscore.
b.) It is better to use a letter than starting with underscores.
c.) Do not use keywords as identifiers (ex: do not name an identifier as int).
d.) Uppercase and Lowercase identifiers are different (Check is different from check).
e.) Be careful when using characters that look similar to each other. For example ‘1’ (the number one) and ‘l’ (the lowercase alphabet L) look alike.
f.) Use names that are easy to understand (if you are storing the salary of a person, name the variable as ‘salary’ instead of declaring it as ‘x’.
g.) Do not use very long names.
h.) Do not name many variables with similar names (avoid using identifiers like: count, counter, counting etc.)

0 comments:

Post a Comment