What are the Tokens in C? Definition, Types, & Uses

By Anjnee Bhatnagar|Updated : August 26th, 2022

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

Tokens in C PDF

As we proceed through the article, we will learn about the use of tokens in C, and the types of tokens available in the C language and we will explain tokens in c programming with the help of examples.

What are Tokens in C?

Tokens are an elementary part of the program. Everything is part of a token from the beginning of the C program, from primary () to the closing parenthesis. Tokens in C programming language is also an important part of the GATE CSE syllabus

Tokens in C Definition

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.

Like C programming, every programming language has its own set of tokens. 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.

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 different token types and then processes these tokens into the next phase until the entire principle is processed. Tickets can be divided into five classes in C. They are:

  • Keywords
  • Identifiers
  • Operators
  • Special Symbols
  • Constants

Let us now briefly discuss each token 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 lowercase and does not contain any particular symbol. Some of the keywords in C programming important for the GATE exam are as follows: Central, volatile, int, getch, signed, void, char, struct, break, continue, etc.

Identifiers in C

An identifier is a name the user or programmer gives 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: function(), int length; here, funct is an identifier used to name a part, and length is an identifier used to call a variable. You can learn the difference between Keywords and Identifiers to know them better. 

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. The ternary operator has a defined condition, resulting in accurate and false conclusions.

Special Symbols in C

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

Constants in C

Constants in C allow a value to remain the same throughout the execution, unlike variables. As per the GATE notes, 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 in C programming language, we cannot modify it throughout the process's lifetime. Some of the examples of constants are 59.88 (floating-point stable), 78(integer constant), byjusEP (String constant), etc.

Tokens in C Language Uses

Well, for instance, say you want to communicate with a person, now if you do not know the language they speak, how will you share with them? You need to know the language they speak similarly 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.

Essential Topics for Gate Exam
Properties of MaterialsResolution of Forces
Riveted JointsSampling Theorem
Single Phase TransformerSoil Classification
Soil FormationStrain Gauge
Tension MembersTest On Hardened Concrete

Comments

write a comment

FAQs on Tokens in C

  • Tokens in C are a fundamental part of the programming language. They are the smallest individual units. Tokens provide functionality for users to interact easily with the compiler.

  • 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.

  • 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.

Follow us for latest updates