The smallest individual units in program are known as tokens. A C++ program is written using these tokens, white spaces and the syntax of the language. C++ has the following tokens.
- Keywords
- Identifiers
- Constants
- Strings
- Operators
1. Keywords:
The keywords implement specific C++ language feature. They are explicitly reserved identifiers and can’t be used as names for the program variables or other user defined program elements.
ISO C++ (C++98) Keywords
• and • and_eq • asm • auto • bitand • bitor • bool • break • case • catch • char • c lass • compl • 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 | • not • not_eq • operator • or • or_eq • private • protected • public • register • reinterpret_cast • return • short • signed • sizeof • static • static_cast • s truct • switch • template | • this • throw • true • try • typedef • typeid • typename • union • unsigned • using • virtual • void • volatile • wchar_t • while • xor • xor_eq |
Note: Old compilers may not recognize some or all of the above keywords
2. Identifiers:
Identifiers refers to the name of variable , functions, array, class etc. created by programmer. Each language has its own rule for naming the identifiers. The following are common rules for both C and C++ to define identifiers.
- Only alphabetic chars, digits and under score are permitted.
- The name can’t start with a digit.
- Upper case and lower case letters are distinct.
- A declared keyword can’t be used as a variable name
- In ANSI C the maximum length of a variable is 32 chars but in c++ there is no bar.
Examples of valid / invalid identifiers:
- a, x, n, num, SUM, fact, grand_total, sum_of_digits, sum1 are valid.
- ab Ab aB AB are treated differently.
- $amount, ‘num’, grand-total, sum of digits, 4num are invalid.
3. Constants:
Constants refer to values that do not change during the execution of a program. Constants can be divided into two major categories:
- Numeric constants
- Integer constants
- Ex: 16, 32768U, 020, 0x10, 012L
- floating point-Real constants
- Ex: 5.19, 0.12E+2, 7.5e-1, 0.00004, 12e0
- Integer constants
- Character Constants
- Single character constants
- Ex: ‘A’ , ‘a’, ‘ ‘, ‘0’, ‘\0’
- String constants
- Ex: “Hello!”
- Single character constants
Escape Sequences or Backslash Character Constants in C++ : C language supports some non-printable characters, as well as backslash ( \ ) which can be expressed as escape sequences. An escape sequence always starts with backslash followed by one or more special characters. For example, a new line character is represented “\n” or endl. These are used in formatting output screen, i.e. escape sequence are used in output functions. Some escape sequences are given below:

4. Strings:
You already know string constants, which were introduced for text output using the cout stream. A string constant consists of a sequence of characters enclosed in double quotes. Ex: “Today is a beautiful day!”.
A string constant is stored internally without the quotes but terminated with a null character, \0, represented by a byte with a numerical value of 0 — that is, all the bits in this byte are set to 0. Thus, a string occupies one byte more in memory than the number of characters it contains. An empty string, “”, therefore occupies a single byte. The terminating null character( ‘\0’ ) is not the same as the number zero and has a different character code than zero. Thus, the string “0” comprises two bytes, the first byte containing the code for the character zero 0 (ASCII code 48) and the second byte the value 0.
Note: C++ supports two types of string representation- the C-Style (Character style) and string class type introduced with standard c++.
5. Operators
An operator is a symbol which represents a particular operation that can be performed on data. An operand is the object on which an operation is performed.C operators can be classified as:
- Arithmetic operators
- Relational operators
- Logical operators
- Assignment operators
- Increment or Decrement operators
- Conditional operator
- Bit wise operators
- unary operator
- Special operators
- Additional operators in c++
You must log in to post a comment.