| Elements of C++ Language |
| |
| Tokens |
| |
| The smallest unit in the program is called a token. C++ has the following tokens: |
| |
| C++ Character Set |
| |
| Character set is a set of valid characters that a language can recognize. A character represents any letter , digit or any sign. The C++ has the following character set |
| |
| Letters: A-Z, a-z |
| |
| Digit: 0-9 |
| |
| Special symbol: Space + - * / ^ \ ( ) [ ] { } = != < > . ' " , $ ; : % ! & ? _ # <= >= @ |
| |
| White Spaces: Blank space, Horizontal tab , New line |
| |
| Other: C++ can process any of the 256 characters as data or as literals. |
| |
| 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: |
| |
| Never start an identifier with anything other than a letter or an underscore.
It is better to use a letter than starting with underscores. |
| |
| Do not use keywords as identifiers (ex: do not name an identifier as int).
Uppercase and Lowercase identifiers are different (Check is different from check). |
| |
| 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. |
| |
| 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’. |
| |
| Do not use very long names. |
| |
| Do not name many variables with similar names (avoid using identifiers like: count, counter, counting etc.). |
| |
| Keywords |
| |
| Keywords are reserved words in C++ programming. They should not be used as identifiers and all keywords should be in lower case. The 63 keywords are tabulated below: |
| |
| asm |
| Auto |
| bool |
| break |
| case |
| catch |
| char |
| class |
| Const |
| const_cast |
| continue |
| default |
| Delete |
| do |
| double |
| Dynamic_cast |
| else |
| enum |
| explicit |
| Export |
| extern |
| false |
| float |
| for |
| friend |
| goto |
| If |
| inline |
| int |
| Long |
| mutable |
| namespace |
| new |
| Operator |
| private |
| protected |
| Public |
| register |
| reinterpret_cast |
| return |
| Short |
| signed |
| sizeof |
| Static |
| static_cast |
| struct |
| switch |
| Template |
| this |
| throw |
| True |
| Try |
| typedef |
| typeid |
| typename |
| union |
| unsigned |
| Using |
| virtual |
| void |
| volatile |
| wchar_t |
| while |
| |
| |
|
| |
| |