What are the Tokens in C?

By Anjnee Bhatnagar|Updated : May 18th, 2022

Tokens in C: In C programming, every word, or operator, that you read is a token. The tokens in C form the elementary part of the program. Every language has tokens, but in this article, we will keep our focus on the tokens in C.

As we proceed through the article, we will learn about the meaning of tokens, the use of tokens in C, and the types of tokens available in the C language.

Table of Content

What is the Meaning of Tokens in C?

Tokens in C are defined as the smallest individual unit in a program. Every chunk of the source code is formed with the help of tokens. Tokens are an elementary part of the program. Right from the beginning of the C program, from main() to the closing parenthesis, everything is a part of a token.

Every programming language has its own set of tokens, just like C programming. A compiler takes the source code from the programmer and processes this source code to generate tokens. This task is assigned to the first phase of the compiler, known as the lexical analysis phase of the compiler.

What is the Use of Tokens in C?

Well, for instance, say you want to communicate with a person, now if you do not know the language they speak, then how will you communicate with them? You need to know the language they speak in a similar manner to interact with the compiler; a program needs to be bonded with tokens.

Tokens give meaning to the source code and provide the functionality to the user to conveniently interact with the compiler.

Types of Tokens in C

In C programming, there are various types of tokens. These tokens in C increase the code readability while providing modularity of code. A compiler breaks down the source code into various token types and then processes these tokens onto the next phase and so on until the entire code is processed. Tokens can be divided into five types in C. They are:

  • Keywords
  • Identifiers
  • Operators
  • Special Symbols
  • Constants

Let us now discuss each token in brief to understand the meaning and usage of tokens in C programming.

Keywords in C

The keywords are predefined words, also known as reserved words. There are 32 keywords present in C programming. A keyword is always in lower case and does not contain any special symbol. Some of the keywords in C programming are as follows: main, volatile, int, getch, signed, void, char, struct, break, continue, etc.

Identifiers in C

An identifier is a name given by the user or programmer to any memory location. They have no predefined meanings attached to them. They can be in upper case or lower case. They allow only underscore and no other special symbol. Example: funct(), int length, here funct is an identifier used to name a function, and length is an identifier used to name a variable.

Operators in C

Operators in C allow the user to perform various arithmetic and logical operations. In C, operators are divided into three types that is Unary operators, binary operators, and Ternary operators. Unary operators consist of a single operator and a single operand, and binary operators consist of two operands with an operator in between, while the ternary operator has a condition defined, resulting in true and false conclusions.

Special Symbols in C

In C, there are various special symbols used to provide the functionality to the user. Some of the special symbols are _ (underscore), *(Asterisk symbol), {}, (), etc. These symbols have special meaning and are therefore called so.

Constants in C

Constants in C allow a value to remain the same throughout the execution, unlike variables. We can define constants in C using two methods:

  • By using preprocessor directives
  • By using the const keyword

Once a value is defined as constant, we cannot modify it throughout the lifetime of the process. Some of the examples of constants are 59.88 (floating-point constant), 78(integer constant), byjusEP (String constant), etc.


write a comment

FAQs on Tokens in C

  • A token is defined as the smallest individual unit present in the program. C language consists of five types of tokens. The C compiler parses the source code to generate tokens. The five types of tokens are:

    Keywords, Identifiers, Operators, Special symbols, and Constants.

  • In C programming, the compiler takes the source code as input and generates tokens. These tokens are then passed on to the next phases of the compiler to scan, detect and handle errors in the code. Tokens are the elementary part of the program.

  • In C programming, tokens form the basis of the source code. An operator is a type of token that allows the user to perform operations like addition, subtraction, logical shifts, etc. In C, operators are divided into three types, which are as follows:

    • Unary operators
    • Binary operators
    • Ternary operators

  • In C programming, tokens are the basic element. Having tokens in a programming language helps in the compilation process. It also helps in increasing the modularity and readability of the code. Tokens are the smallest individual unit of a program.

Follow us for latest updates