Introduction to C tokens
Introduction to C tokens
Introduction to C tokens
Introduction to C tokens.
Objectives
To understand the concept of tokens in C programming.
Introduction
In the C programming language, tokens are the smallest individual units of a program. They serve
as the building blocks of C code and are essential for understanding how to write, interpret, and
analyze C programs. This lab introduces C tokens, such as keywords, identifiers, constants,
operators, and special symbols. Understanding these tokens is fundamental to developing a solid
foundation in C programming, as they dictate the syntax and structure of the language. This report
details each category of tokens, describes their roles in the C programming language, and
In programming languages, tokens are the smallest units of a program. In C, tokens are individual
components that collectively define the syntax and structure of a program. Tokens include
keywords, identifiers, constants, strings, operators, and punctuation symbols. Understanding these
tokens is fundamental for writing C programs, as each token plays a unique role in defining the
logical flow and instructions in a program. By learning about tokens, we gain foundational
1. Arithmetic Operators:
Arithmetic operators are used for performing basic mathematical operations. In C, these include +
(addition), - (subtraction), * (multiplication), / (division), and % (modulus). For instance, using the
operator + in a + b will add two numbers stored in variables a and b.
2. Relational Operators:
Relational operators help in comparing two values and return a boolean result. Common relational
operators in C are == (equal to), != (not equal to), > (greater than), < (less than), >= (greater than
or equal to), and <= (less than or equal to). They are primarily used in conditional statements.
3. Logical Operators:
Logical operators are used to combine multiple conditions in control statements. The main logical
operators in C are && (logical AND), || (logical OR), and ! (logical NOT). They play a crucial
role in evaluating complex conditions.
4. Bitwise Operators:
Bitwise operators perform operations at the bit level. The operators include & (AND), | (OR), ^
(XOR), ~ (NOT), << (left shift), and >> (right shift). They are useful in low-level programming,
such as setting or clearing specific bits.
5. Assignment Operators:
Assignment operators are used to assign values to variables. The simplest assignment operator is
=. Compound assignment operators such as +=, -=, *=, and /= combine arithmetic and assignment
operations, which help simplify code.
Triangular Series
#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
{
printf("\n");
}
}
return 0;
}
Output:
Area of Rectangle:
Triangular Series:
Determine the largest and smallest number among three numbers:
Determine the largest and smallest number among four numbers:
Conclution
Understanding tokens in C is fundamental for programming in C, as every statement relies on
tokens to convey commands to the computer. Each type of token has a unique role, contributing to
the language's syntax and functionality. Practicing with tokens enables programmers to write
This lab provided a solid understanding of the six main types of tokens in C and their roles in
program structure. By working with operators we gained insight into how C programs are
constructed. We understannd the necessity of correctly using each token to avoid syntax errors
during compilation. Mastery of tokens is essential for writing effective and error-free C code,