Skip to main content

TOKENS ,IDENTIFIERS & CONSANTS

TOKENS 
 Tokens  are  the  basic  buildings  blocks  in   language  which  are constructed  together  to  write  a   program.Tokens is each  and  every  smallest  individual  units  in  a   program  are known  as   tokens. 

C++  tokens  are six type .
  1. Keywords  :    struct ,break , else long , switch , case ,enum , register  , typedef.
  2. Identifiers  :main,  total.
  3. Constants  : 3.14 .
  4. Strings : "hello", "string".
  5. Operators :  +, - ,/ ,*.
  6. Special  symbols : (),{}.

Example
#include<iostream.h>
#include<Conio.h> 
                   int  main() 
               { 
                   int  a,  b,  total; 
                   a  =  10,  b =  20;
                   total  =  a  +  b; 
        cout<<“Total  =  ”<<  total<<endl; 
                } 
Explanation 
  1. main  –  identifier .
  2. {,},  (,)  –  delimiter .
  3. int  –  keyword .
  4.  +  ,  =  ,  <<  -  operators.
  5.  a,  b,  total  –  identifier .
  6. main,  {,  },  (,  ),  int,  a,  b,  total,+,  =,<<  –  tokens .
IDENTIFIERS  
  •  Each  program  elements  in  a    program  are  given  a  name called  identifiers. 
  •  Names  given  to  identify  Variables,  functions  and  arrays  are examples for  identifiers.     eg.  int  a; 
  • a is  a  name given  to  integer  variable   
Constants
Constants refers  to  the  data  items  that  do  not  change  their value  during  the  program  execution.  Several  types  of  C  constants that  are allowed  in  C ++ : 
1.  Integer  Constants 
Integer  constants  are  whole  numbers  without  any  fractional  part.  It must  have  at  least  one  digit  and  may  contain  either  +  or  –  sign.  A number  with  no  sign  is  assumed  to  be positive. There are three  types  of  integer  constants: 
  • Decimal  Integer  Constants :Integer  constants  consisting  of  a  set  of  digits,  0  through  9, preceded  by  an  optional  –  or  +  sign. Example of valid 143,    -231,    0.
  •  Octal  Integer constants :Integer  constants  consisting  of  sequence  of  digits  from  the  set 0  through  7  starting  with  0  is  said  to  be  octal  integer constants. Example of valid octal Hexadecimal we  Integer Constants integer constants 
  • Hexadecimal  integer  constants : are  integer  constants  having sequence  of  digits  preceded  by  0x  or  0X.  They  may  also include alphabets  from  A  to  F  representing  numbers  10  to  15. Example of valid 0xD,  0X8d,  0X,  0xbD.
  • Real Constants The numbers having fractional parts are called real or floating point constants. These may be represented in one of the two forms called fractional form or the exponent form and may also have either + or – sign preceding it. Example of valid real constants in fractional form or decimal notation 0.05, -0.905, 562.05, 0.015 , 252E85, 0.15E-10,  -3e+8 .
  1. Character Constants 
A character constant contains one single character enclosed within single quotes. Examples of valid character constants ‘a’ , ‘Z’,  ‘5’ It should be noted that character constants have numerical values known as ASCII values, for example, the value of ‘A’ is 65 which is its ASCII value.
 String Literals 
String literals or constants are enclosed in double quotes "".  Here are some examples of string literals. All the three forms are identical strings.  eg. "Hello".

Comments

Popular posts from this blog

Simple hello world program and explanation

HELLO WORLD PROGRAM AND EXPLANATION • Hello world program # include<iostream.h>  #include<conio.h> // pre-processor directives ,header files          Void main () // main () is where program execution start           {                 Clrscr (); //its clear output of the previous  program.               Cout<<”HELLO WORLD”;         // prints hello world .               Getch();        //its hold the output screen of the program.                       }                         OutPut                  HELLO WORLD Explanation Above program is the simple c++ program  which pri...