Keywords in C++

Keywords in C++

Examples for names

valid:
   a US us VOID
   _var SetTextColor
   B12 top_of_window
   a_very_long_name123467890
invalid:
   goto 586_cpu object-oriented
   US$ true écu

Valid Names

Within a program names are used to designate variables and functions. The following rules apply when creating names, which are also known as identifiers:
  • a name contains a series of letters, numbers, or underscore characters ( _ ). German umlauts and accented letters are invalid. C++ is case sensitive; that is, upper- and lowercase letters are different.
  • the first character must be a letter or underscore
  • there are no restrictions on the length of a name and all the characters in the name are significant
  • C++ keywords are reserved and cannot be used as names.
The opposite page shows C++ keywords and some examples of valid and invalid names.
The C++ compiler uses internal names that begin with one or two underscores followed by a capital letter. To avoid confusion with these names, avoid use of the underscore at the beginning of a name.
Under normal circumstances the linker only evaluates a set number of characters, for example, the first 8 characters of a name. For this reason names of global objects, such as functions, should be chosen so that the first eight characters are significant.

Conventions

In C++ it is standard practice to use small letters for the names of variables and functions. The names of some variables tend to be associated with a specific use.
Examples:
c, ch               for characters
i, j, k, l, m, n    for integers, in particular indices
x, y, z             for floating-point numbers
To improve the readability of your programs you should choose longer and more self-explanatory names, such as start_index or startIndex for the first index in a range of index values.
In the case of software projects, naming conventions will normally apply. For example, prefixes that indicate the type of the variable may be assigned when naming variables.

Post a Comment

0 Comments