Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Operators Part 1: Arithmetic & Relational

Lesson 7 of 53 in the free Foundation of C & C++ notes on Siksha Sarovar, written by Rohit Jangra.

The Verbs of Your Program

Operators are symbols that tell the C compiler to perform specific mathematical or logical transformations on your data (which are called "operands").

1. Arithmetic Operators

Used for basic calculations.

OperatorNameDescriptionExample (a=10, b=3)Result
+AdditionSum of valuesa + b13
-SubtractionDifferencea - b7
*MultiplicationProducta * b30
/DivisionQuotienta / b3
%ModuloRemaindera % b1

The Integer Division Rule: In C, if you divide two integers, the result is always an integer. Any decimal portion is truncated (simply thrown away). It is not rounded!

  • 5 / 2 results in 2.
  • To get a decimal result (2.5), at least one side must be a float: 5.0 / 2.

The Modulo Operator (%): This returns the remainder left over after division.

  • 10 % 3 = 1 (because 3 goes into 10 three times with 1 left over).
  • 10 % 2 = 0 (no remainder).
  • Pro Tip: Use modulo to check if a number is even (n % 2 == 0) or odd (n % 2 != 0).

2. Relational Operators (Comparisons)

Used to compare two values. These operators always return a boolean-like result: 1 (True) or 0 (False).

OperatorMeaningExample (a=10, b=20)Result
==Equal toa == b0
!=Not equal toa != b1
>Greater thana > b0
<Less thana < b1
>=Greater or equala >= 101
<=Less or equalb <= 150

Type Casting: Changing Types on the Fly

Sometimes you need to treat an int as a float temporarily, especially for division.

int totalMarks = 450;
int totalSubjects = 5;
float average = (float)totalMarks / totalSubjects; // Type casting

Expression Evaluation

C follows rules similar to math (PEMDAS). Multiplication and Division are done before Addition and Subtraction.

int res = 10 + 5 * 2; // res is 20, not 30!
Parentheses are Free! Use them liberally. 10 + (5 2) is much clearer than 10 + 5 2. It makes your intent obvious to anyone reading your code.