Operators in C Program
Operators in C Program
Arithmetic operators
Relational operators
Logical operators
Bitwise operators
Assignment operators
Conditional operators
Special operators
Arithmetic operators
C supports all the basic arithmetic operators. The following table shows all the basic
arithmetic operators.
Operator Description
% remainder of division
Relational operators
The following table shows all relation operators supported by C.
Operator Description
> Check if operand on the left is greater than operand on the right
Logical operators
C language supports following 3 logical operators. Suppose a = 1 and b = 0,
Operator Description Example
|| Logical OR (a || b) is true
Bitwise operators
Bitwise operators perform manipulations of data at bit level. These operators also
perform shifting of bits from right to left. Bitwise operators are not applied
to float or double(These are datatypes, we will learn about them in the next
tutorial).
Operator Description
| Bitwise OR
^ Bitwise exclusive OR
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
The bitwise shift operator, shifts the bit value. The left operand specifies the value to
be shifted and the right operand specifies the number of positions that the bits in the
value have to be shifted. Both operands have the same precedence.
Example :
a = 0001000
b = 2
a << b = 0100000
a >> b = 0000010
Assignment Operators
Assignment operators supported by C language are as follows.
+= adds right operand to the left operand and assign a+=b is same as a=a+b
the result to left
-= subtracts right operand from the left operand and a-=b is same as a=a-b
assign the result to left operand
*= mutiply left operand with the right operand and a*=b is same as a=a*b
assign the result to left operand
/= divides left operand with the right operand and a/=b is same as a=a/b
assign the result to left operand
%= calculate modulus using two operands and assign a%=b is same as a=a%b
the result to left operand
Conditional operator
The conditional operators in C language are known by two more names
1. Ternary Operator
2. ? : Operator
Explanation:
Special operator