Wednesday, 21 March 2018

C++ Tokens

The smallest individual units in a program is known as Tokens.
The C++ programs are written by using these tokens , white spaces and syntax of the language.
C++ has following Tokens 
  1. Keywords
  2. Identifiers
  3. Constants
  4. Strings
  5. Operators

Keyword :-
  Keyword are those words meaning whose meaning is known to the compiler or whose meaning is already defined by compiler.
 Keywords are also called as reserved words.Keywords should not be used in variable declaration.
 Following are some example of keywords
   auto , break , case , char , class , const , continue , default,..........................................

Identifiers :-
  Identifiers refers to the name of the variables , functions , arrays , classes created by the programmer.
  Rules of Naming identifiers:-
   1. Only alphabets , digits , and underscore are permitted.
   2. Variable name should not start with digit.
   3. Uppercase and lowercase letter are distinct.
   4. Keywords should not be used as name of the identifier.
   5. 'C' recognizes 32 characters in name of the identifiers but C++ has no limit on its length.

Constant :-
  Each primitive data type has their own constant value declaration also called as literals.

Primary Constant
  a. Integer Constant
  b. Real Constant 
  c. Character Constant

Secondary Constant
  a. Array
  b. Pointer
  c. Structure and unions
  d. Enum

Primary Constant
 Integer Constant :-
   1. Integer constant must have at least one digit.
   2. They must not have a decimal point.
   3. They can be positive or negative.
   4. If there is no any sign to integer it is assume to be positive.
   5. No comma or blank spaces are allowed within the integer constant.
          e.g.  426, +756 , -588 etc.

Real Constant :-
   1. These are generally called as floating point constant.They can be written two forms.That is , fractional form & exponential form.
  2. Real constant can be positive or negative.
  3. They must have decimal point.
  4. Default sign is positive.
  5. No comma or blank spaces are allowed in the real number.
       e.g. 22.45 , -85.23 , -11.20 , +3.211e-4 , 5.6e4 etc.

Character Constant :-
   1. The character constant is a single alphabet or a single digit or s single special symbol enclosed within the single quotation marks.
   2. Maximum length of a character is one character.

1 comment:

Popular Posts

Categories

Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (85) R (69) Selenium Webdriver (2) Software (13) SQL (27)