Tokens in C++ - Leo tutorials


The smallest individual units in a program are known as tokens. C++ has the following tokens :


  1. Keywords,
  2. identifiers,
  3. constants,
  4. strings
  5. operators.
A C++ program is written using these tokens, white spaces, and the syntax of the language.

  • Keywords : The keywords implements specific C++ language features. They are explicitly reserved identifiers and can not be used as names for the program variables or other user defined program elements.

  • Identifiers : Identifiers refer to the name of variables, functions, arrays, classes, etc., created by the programmer. They are the fundamental requirement of any language. Each language has its own rules for naming these identifiers. The following rules are as follows
  1. Only alphabetic characters, digit and underscores are permitted.
  2. The name cannot start with a digit.
  3. Uppercase and lowercase letters are distinct.
  4. A declared keyword cannot be used as a variable name.
ANSI C++ placed no limit on its length and, therefore, all the character in a name are significant.
  • Constant : Constant refer to fixed values that do not changes during the execution of a program.
               C++ support several kinds of literal constants. They include integers, characters, floating point numbers and strings. Literal constants do not have memory locations.

         Example :
12.34       (floating point integer)
037          (octal integer)
"C++"     (string constant)
L'ab'        (wide-character constant)
 The wehar_t type is wide-character literal introduced by ANSI C++ and is introduced for character sets that cannot fit a character into a single byte wide-character literal being with letter L.

  • Strings : C++ does not support a built-in-string type.Generally we use null-terminated character arrays to store and manipulate strings. These string are called C-string or C-style strings.
                ANSI standard C++ now provides a new class called string. In many situations the string objects may be used like any other built-in type data. For using the strings class, we must include <string> in our program.
                 The string class is very large and includes many constructors, member functions and operators.
  • Operators : C++ has  a rich set of operators, All operators are valid in C++ also. Which are as follows:
  1. arithmetic operators : +,-,/,%
  2. relational operators : <,<=,>,>=,==,/=,
  3. logical operators : &&,II,!
  4. increments and decrements operators : ++,--
  5. Condition operator : ? :
  6. bit-wise operators : &,!<<,>>
  7. Special operators : (comma), size of

Post a comment

0 Comments