What is Operator? Simple answer can be given using expression 4 + 5 is equal to 9. Here 4 and 5 are called operands and + is called operator. C language supports following type of operators.
· Arithmetic Operators· Logical (or Relational) Operators· Bitwise Operators·. Assignment Operators· Misc OperatorsLets have a look on all operators one by one.
Arithmetic Operators:
There are following arithmetic operators supported by C language:
Assume variable A holds 10 and variable B holds 20 then:
Try following example to understand all the arithmatic operators. Copy and paste following C program in test.c file and compile and run this program.
#include<stdio.h>#include<conio.h>main(){int a = 21;int b = 10;int c ;c = a + b;printf("Line 1  Value of c is %d\n", c );c = a  b;printf("Line 2  Value of c is %d\n", c );c = a * b;printf("Line 3  Value of c is %d\n", c );c = a / b;printf("Line 4  Value of c is %d\n", c );c = a % b;printf("Line 5  Value of c is %d\n", c );c = a++;printf("Line 6  Value of c is %d\n", c );c = a;printf("Line 7  Value of c is %d\n", c );getch();}This will produce following result
Line 1  Value of c is 31Line 2  Value of c is 11Line 3  Value of c is 210Line 4  Value of c is 2Line 5  Value of c is 1Line 6  Value of c is 21Line 7  Value of c is 22
Logical (or Relational) Operators:
There are following logical operators supported by C language
Assume variable A holds 10 and variable B holds 20 then:
Try following example to understand all the Logical operators. Copy and paste following C program in test.c file and compile and run this program.
#include<stdio.h>
#include<conio.h>
main()
{
int a = 21;
int b = 10;
int c ;
if( a == b )
{
printf("Line 1  a is equal to b\n" );
}
else
{
printf("Line 1  a is not equal to b\n" );
}
if ( a < b )
{
printf("Line 2  a is less than b\n" );
}
else
{
printf("Line 2  a is not less than b\n" );
}
if ( a > b )
{
printf("Line 3  a is greater than b\n" );
}
else
{
printf("Line 3  a is not greater than b\n" );
}
/* Lets change value of a and b */
a = 5;
b = 20;
if ( a <= b )
{
printf("Line 4  a is either less than or euqal to b\n" );
}
if ( b >= a )
{
printf("Line 5  b is either greater than or equal to b\n" );
}
if ( a && b )
{
printf("Line 6  Condition is true\n" );
}
if ( a  b )
{
printf("Line 7  Condition is true\n" );
}
/* Again lets change the value of a and b */
a = 0;
b = 10;
if ( a && b )
{
printf("Line 8  Condition is true\n" );
}
else
{
printf("Line 8  Condition is not true\n" );
}
if ( !(a && b) )
{
printf("Line 9  Condition is true\n" );
}
}
This will produce following result
Line 1  a is not equal to b
Line 2  a is not less than b
Line 3  a is greater than b
Line 4  a is either less than or euqal to b
Line 5  b is either greater than or equal to b
Line 6  Condition is true
Line 7  Condition is true
Line 8  Condition is not true
Line 9  Condition is true
Operator
Description
Example
==
Checks if the value of two operands is equal or not, if yes then condition becomes true.
(A == B) is not true.
!=
Checks if the value of two operands is equal or not, if values are not equal then condition becomes true.
(A != B) is true.
>
Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true.
(A > B) is not true.
<
Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true.
(A < B) is true.
>=
Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true.
(A >= B) is not true.
<=
Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.
(A <= B) is true.
&&
Called Logical AND operator. If both the operands are non zero then then condition becomes true.
(A && B) is true.

Called Logical OR Operator. If any of the two operands is non zero then then condition becomes true.
(A  B) is true.
!
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
!(A && B) is false.

Bitwise operator works on bits and perform bit by bit operation.
Assume if A = 60; and B = 13; Now in binary format they will be as follows:
A = 0011 1100
B = 0000 1101

A&B = 0000 1100
AB = 0011 1101
There are following Bitwise operators supported by C language
Assignment Operators:There are following assignment operators supported by C language: Try following example to understand all the Assignment Operators. Copy and paste following C program in test.c file and compile and run this program.
Short Notes on LVALUE and RVALUE:x = 1; takes the value on the right (e.g. 1) and puts it in the memory referenced by x. Here x and 1 are known as LVALUES and RVALUES respectively Lvalues can be on either side of the assignment operator where as Rvalues only appear on the right. So x is an Lvalue because it can appear on the left as we've just seen, or on the right like this: y = x; However, constants like 1 are Rvalues because 1 could appear on the right, but 1 = x; is invalid.
Operators Categories:

