Skip to main content

Tokens and its types in 'C'

   Tokens are the smallest individual unit of a program or in simple words it is a main part of C program.Tokens are the building blocks of any program. The smallest individual and basic unit of a C programming is called c tokens.
  
  *    Normally there are six types of tokens in C:-

i> Keywords:-
         Keywords are special words that are used to give a special meaning to the program and can't be used as variable and constant.They are basically a sequence of characters that have fixed to mean. For example:-
                auto     double      long     break
                float    short        char     if
               while    continue   int       void etc.
All keywords must be written in lower case.It is 32 in number.


ii> Identifiers:-
        The identifiers are basically a token. It can be a variable's name or a label's name. So identifiers are actually a user defined data. But there are certain rules to frame an identifier. They are as follows:-
  *  An identifier can have alphanumeric characters and underscore. i.e A-Z , a-z , 0-9 , _ .

  *  But it should always start with an alphabet or underscore.Not with a number.

  *  It should not be a reserved keyword.

  *  identifiers are actually case sensitive in C language. So flag and FLAG are actually different.

  *  Use of special characters is forbidden.

Also avoid starting an identifier with underscore because compiler thinks that it is system defined.


iii> Variables:-
         The variables are used to give the name and allocate memory space. An entity that may vary during execution. Variables are the data item whose value may vary during the execution of the C program. A specific location or address in thre memory is associated for each variable and value of that variable is stored in that locatuion . All the variables must have their type indicated so that the compiler can recoard all the necessary information about them and generate the appropriate code during translation.
 There are some rules to name a variable:-
  *  variable name must not start with a digit.

  *  Variable name can consist of alphabets, digits and special symbols like underscore.


  *  Blanks or spaces are not allowed in variable name.


  *  Keywords are not allowed as variable name.


  * upper and lower case names are treated as different ,as C is case-sensitive, so it is suggested to       keep the variable names in lower case.


  

iv> Constants:-
           The quantity which does not change during the execution of a program is known as constant. It is use in assignment statements.Constants are stored in variables. There are five types of constant:-
  *  Character 

  *  Integer


  *  Real (float)


  *  String


  *  Logical


 A character constant is a constant which uses single quotation around characters. For example: 'a' , 'l' etc. An integer constant is a numeric constant without any fractional or exponential part.

 A floating point constant is a numeric constant that has either a fractional form or an exponential form.
 String constants are the constants which are enclosed in a pair of double-quote marks. For example: "good" , " ", "x" .


v> String:-

        String is a collection of more than one character. For ex: "RAM" , " Meerut" . String is represented by a pair of double quotes. the length of a string is determined by a terminating null character('\0') . For using string the header file <string.h> is needed. The nine more commonly used functions in the string library are:-
  *  strcat-- concatenates two strings.

  *  strchr--  string scanning operation.

  *  strcmp-- compair two string.

  *  strcpy-- copy a string.

  *  strlen--  get string length.

  *  strncat--  concatenate one string with part of another.

  *  strncmp--  compare part of two strings.

  *  strncpy--  copy part of a string.

  *  strrchr--string scanning operation.


 vi> Operators:- 
            Operators acts as connectors and they indicate what type of operation is being carried out. The values that can be operated by these operators are called operands. They are used to perform basis operations , comparision , manipulation of bits and so on. The operators include many types which are as follows:-
  *  Arithmetic operators.

  *  Logical operators.

  *  Relational operators.

  *  Assignment operators.

  *  Increment/ Decrement operators.

  *  Bitwise operators.

  *  Special operators.

Comments

Post a Comment

Please comment.

Popular posts from this blog

Process Scheduling And Types of Process Schedular :-

        ⇰ PROCESS SCHEDULING Process Scheduling  is a task  of Operating System that schedules processes of different states like new, ready, waiting, terminated  and running.This scheduling helps in allocation of CPU time for each process, and Operating System allocates the CPU time for each procss. And the process scheduling plays important role to keep the CPU busy all the time.  ⏩   Followings are some objectives of Process Scheduling :-  i > To increase the amount of users within acceptable response times.  ii > To maintain the balance between response and utilization of system. iii > To decrease the enforce priorities and  give reference to the processes holding the key resources.      ⇰  PROCESS SCHEDULAR A scheduler carries out the pro cess scheduling work. Schedulers are often implemented so they keep all computer resources busy and  allows multiple users to shar...

Process & Its state And process control block :-

                ⇰  PROCESS :- A process can be thought of as a program in execution. Means when any program is executed it becomes process. A processwill need certain resources such as CPU time , memory, files and I/O devices to complete its task. These resources are allocated to the process either when it is created or at the time of execution.             A process is the unit of work in most systems. A system consistes of a collection of processes. All these processes may execute concurrently. Traditionally a process contained only a single thread. Most modern operating ststems now supports processes that have multiple threads.         The operating system is responsible for several important works of process management as - the creation and deletion of process, the schrduling of process, communication and deadlock handling of process. Process is broudly divided into two ...