C Tokens Tutorial With Example From Scratch

C Tokens Tutorial With Example From Scratch is today’s topic. The C program consists of various types of tokens and tokens are either keywords, identifiers, constants, string literals, or symbols. C tokens are the basic buildings blocks in C language which are constructed together to write a C program. Every smallest individual unit in a C program is known as C tokens.

C Tokens Tutorial With Example From Scratch

Let us take a primary example of Token.

#include <stdio.h>
int main()
  int x, y, total;
  x = 10, y = 21;
  total = x + y;
  printf ("Total = %d \n", total);

Here, the tokens are the following.

main, {, }, (, ), int, x, y, +, =, total are the tokens.

So, C Language has following tokens

  • Identifiers
  • Keywords
  • Constants
  • Operators
  • Special characters

Identifiers in C Language

Identifiers in C Language refers to the name of the variables, functions, arrays, etc. created by the programmer, using the combination of the following characters.

  • Alphabets: A to Z     (or)    a to z
  • Digits :     0 to 9
  • Underscore: _

The first character of an identifier must be either alphabet or underscore; we can’t use digit. In the above example, x, y, total is the identifier.

Keywords in C Language

Keywords in C Language are the words whose meaning is already explained by the c compiler. That means at the time of designing the language; some words are reserved to do the specific tasks. Such words are called keywords (or) reserved words. Keywords are pre-defined words in a C compiler. Since keywords are referred names for the compiler, they can’t be used as the variable name. C language supports 32 keywords.

Constants in C Language

Constants define fixed values, that does not change during the execution of a program. C supports the following constants. There are many types of constants like below.

  • Integer constants
  • Character constants
  • Real or floating constants
  • String constants

Operators in C Language

The operator is the symbol which performs the particular operation in C Language. C supports the rich set of operators. C operators can be classified into many of categories. They include the arithmetic operators, logical operators, bitwise operators, etc. In the above example, +, = is the operators.

Special characters in C Language

All characters other than alphabets and digits are treated as special characters. In the above example, {, }, (, ) are the special characters.

Finally, C Tokens Tutorial With Example is over.


Post Your Thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.