An operator is a symbol that performs the operations between two operants. An operant may be a variable or a constant. C language supports a rich set of operators.
Typesof Operators in C Programming:
Table of Contents
Arithmetic Operators:
- Arithmetic Operators are used to perform arithmetic operations between two operants.
Ex: +, -, *, /, %
Ex: 10/3=3, 10/3.0 = 3.33, 4%3=1, 3%4=3
Note: The modulus operator is used only for integer data type and the forward slash symbol (/) is used to perform integer division.
Relational Operators:
- The relational operators are used to compare two similar quantities. An expression is said to be a relational expression if the expression has relational operators. Relational expressions always produce logical values i.e., true or false.
Ex: <, β€, >, β₯, ==, !=
Ex: a>b
Logical Operators:
- An expression that contains logical operators is called a logic expression or compound relational expression. Generally, we use logical operators when we want to specify more than one condition.
Ex: logical and (&&)
Logical or (||)
logical not (!)
Assignment Operator:
- The assignment operator is used to assign the value of the right-hand side of the expression to the variable which is present on the left-hand side of the expression. The assignment operator in C language is β=β.
- The syntax is
- Variable = expression or constant or variable.
c = a + b
c=10, c=b.
We can also specify the shorthand form of the assignment operator.
Ex: x+ = 3 π‘ͺ x = x+3
y- = 5 π‘ͺ y=y-5
a% = b π‘ͺ a= a%b
n/ = 10 π‘ͺ n = n/10
Increment/Decrement Operators:
- The C language has two very useful and powerful operators called increment/decrement operators.
- The increment operator is defined by ++ and this operator is used to increment the value of the variable by one.
- The decrement operator is defined by β and this operator is used to decrease the value of the variable by one.
- Generally, these operators are used in loops.
Ex: x++, ++x, y–, –y
x++ means post-increment.
++x means pre-increment.
- Post increment/decrement operator means first we specify the variable and then the operator.
Ex: x++, yβ
- Pre increment/decrement operator means first we specify the operator and then the variable.
Ex: ++x, –y
- Pre increment/decrement, and post increment/decrement operators are the same if they have been used independently.
- They behave differently when they are combined with an expression or with printf statements.
Bitwise Operators:
- Bitwise operators are used for the manipulation of the data at the bit level. Bitwise operators are also to shift the bits either to the left side or right side. The different bitwise operators are:
Note: these operators can be performed only on integer data types.
- Bitwise AND (&): The bitwise operator is used to type and perform a bitwise landing between the two operants. The result of these operators is one when both the inputs are 1. Otherwise, the result is 0.
Ex: a= 10 -> 00001010 (bits)
B =14 -> 00001110 (Bits)
a&b = 00001010
a&b = 10
- Bitwise OR (|): Bitwise OR operator is used to perform a bitwise oring operation between two operants. The result of this operator is 0 when both the inputs are 0 otherwise the result is 1.
Ex: a=10 -> 00001010 (changed to bits)
b=14 -> 00001110 (changed to bits)
a|b = 00001110
a|b = 14
- Bitwise Exclusive OR(β): Bitwise exclusive OR operator is used to perform bitwise exclusive oring operation between the two operants. The result of this operator is 0 when both the inputs are the same otherwise the result is 1.
Ex: a =10 -> 00001010 (changed to bits)
B = 14 -> 00001110 (changed to bits)
aβb = 00000100
aβb = 4.
- Bitwise left shift operator (<<): Bitwise left shift operator is used to shift the bits of an operant to the left side by specifying the number of bits.
a = 10 -> 00001010 (changed to bits)
a<<1 00010100 -> 20 (changed to numeric)
a<<2 00101000 -> 40 (changed to numeric)
Note: whenever we shift the bits towards the left side by one position it indicates that the value of the variable is multiplied by 2.
- Bitwise right shift operator (>>): This operator is used to shift the operant to the right side by specifying the number of bits.
a= 10 00001010 -> 10
a>>1 00000101 β 5
a>>2 00000010 -> 2
Note: when we shift the bits towards the right side by one position it indicates that the value of the variable is divided by 2.
- Bitwise Complement Operator: The Bitwise complement operator is used to give the compliment values of the bit. If we give zero, the compliment is one. If we give one, the compliment is zero.
Special operators:
- The special operators that are available in C language are comma operator, size of the operator, pointer operator (x, &), and member selection operator (., π‘ͺ)
- Comma operator (,): The comma operator is used when we want to separate the variables or to separate the message from the variables.
Ex: Int a, b, c;
Printf(β the value of c%d\nβ, c);
Conditional Operator (?, :):
- A Conditional Operator is also called a ternary operator. The conditional operator is going to contain two operators and three operants. The syntax of the conditional operator is
(expression1)? (expression2):(expression3);
- First, it evaluates expression 1. Expression 1 might be a logical expression or relational expression. [it is an alternative to if-else statement]
- If expression 1 evaluates true value then it executes expression 2.
- If expression 1 evaluates false value then it executes expression 3.
Ex: (10>7) a=10, b=7
(a>b)? printf(βa is largestβ): printf(βb is largest);
- Left to Right associativity evaluates the expression from left to right conversely right to left associativity evaluates the expression from right to left.
- The presidency table is given below:
Ex: Let a=9, b=12, c=3, d=1, e=2, f=3,g=1,h=4.
X = a x b βc = 9 x 12 -3 =105
Y = a β b/c +d/a
= 9 β 12/3 + 1/9
= 5 + 1/9
= 5 + 0 = 5.
Z = a-(b/(3+c)x2)-d
= 9-(12/(6)x2)-1
=9-4-1
= 4.
X = a/b + c x d β 5
= 9/12 + 3 x 1 -5
=0 +3-5
= -2.
X = a/b + c x d β e&&f- !g/h
= 9/12 + 3 x 1 β 2&&3 -! 1/4
= 0 +3 β 2&&3 β 0
=1 && 3.
Side-Effect:
- A side-effect is an action that results from the evaluation of an expression.
Ex: a=3, b=4, c=5
X=a+b+c [no side-effect]
a=b+c [side effect]
The presidency table is given below:

FAQs
What is the difference between unary, binary, and ternary operators?
Unary operators: Operate on a single operand (e.g., -5, !flag).
Binary operators: Operate on two operands (e.g., 5 + 3, x > y).
Ternary operators: Operate on three operands (e.g., condition ? value_if_true : value_if_false).What are operator precedence and associativity?
i) Operator precedence determines the order in which operators are evaluated in an expression.
ii) Operator associativity determines the grouping of operators with the same precedence (left-to-right or right-to-left).What is the modulo operator (%)?
The modulo operator calculates the remainder when one number is divided by another.
What are the short-circuit logical operators?
The && (logical AND) and || (logical OR) operators are short-circuit operators. This means that the second operand is only evaluated if necessary.