# Chapter 8: Operators

Definition

An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations with data and variables. They usually form a part of the mathematical or logical expressions.

The different categories of C operators are:

Arithmetic Operators

OperatorDescriptionExample
+Adds two operands and produces suma = 2, b = 5
c = a + b
c stores 7
-Subtracts two operands and produces differencea = 2, b = 5
c = a - b
c stores -3
*Multiplies two operands and produces producta = 2, b = 5
c = a * b
c stores 10
/Divides two operands and produces quotienta = 2, b = 5
c = a / b
c stores 0
%Divides two operands and produces remaindera = 2, b = 5
c = a % b
c stores 2

Relational Operators

OperatorDescriptionExample
>If the 1st operand is greater than the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = a > b
c stores 0
>=If the 1st operand is greater than OR equal to the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = a >= b
c stores 0
<If the 1st operand is less than the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = a > b
c stores 1
<=If the 1st operand is less than OR equal to the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = a >= b
c stores 1
==If the 1st operand is equal to the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = (a == b)
c stores 0
!=If the 1st operand is NOT equal to the 2nd operand, returns 1 (for true) otherwise 0 (for false)a = 2, b = 5
c = (a != b)
c stores 1

Logical Operators

OperatorDescriptionExample
&&This is Logical AND operator.
1 && 1 returns 1
1 && 0 returns 0
0 && 1 returns 0
0 && 0 returns 0
a = 2, b = 5, c = 2, d = 7
c = (a < b) && (c != d)
1st operand is (a < b), returns 1
2nd operand is (c != d), returns 1
c stores 1
||This is Logical OR operator.
1 || 1 returns 1
1 || 0 returns 1
0 || 1 returns 1
0 || 0 returns 0
a = 2, b = 5, c = 2, d = 7
c = (a > b) && (c == d)
1st operand is (a > b), returns 0
2nd operand is (c == d), returns 0
c stores 0
!Complements the content of a variablea = 2, b = 5
c = a > b
c stores 1
d = !c
d stores 0

Assignment Operators