What are the tokens in C ?

CServer Side ProgrammingProgramming

A token is nothing but a smallest element of a program which is meaningful to the compiler. The compiler that breaks a program into the smallest units is called tokens and these tokens proceed to the different stages of the compilation.

Types

Tokens are classified into different types, which are mentioned below −

  • Keywords
  • Identifiers
  • Constants
  • Strings
  • Special Symbols
  • Operators

Example

Given below is the C program the use of identifiers, keywords, variables etc.

 Live Demo

#include <stdio.h>
int main(){
   int a,b,c;
   printf("enter a and b values: \n");
   scanf("%d%d",&a,&b);
   c=a*b;
   printf("value of c=%d",c);
   return 0;
}

Output

When the above program is executed, it produces the following result −

enter a and b values:4 5
value of c=20

In the above program,

  • main is the identifier.
  • int is the keyword.
  • { } are the delimiters.
  • a,b,c are the variables.

All together are called as tokens.

raja
Published on 03-Sep-2021 07:12:43
Advertisements