OPERATORS IN C LANGUAGE
* An Operator is a symbol used to perform operation
in given programming language.
Types of operators in C language
1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
1. Arithmetic Operators
Addition +
Subtraction -
Multiplication *
Division /
Modulus %
#include <stdio.h>
int main()
{
int a;
int b;
a = 34;
b = 6;
printf("a + b = %d\n" ,a+b);
printf("a - b = %d\n" ,a-b);
printf("a * b = %d\n" ,a*b);
printf("a / b = %d\n" ,a/b);
return 0;
}
#include <stdio.h>
int main()
{
int a;
float b;
a = 22;
b = 3;
printf("a + b = %f\n", a+b);
printf("a - b = %f\n", a-b);
printf("a * b = %f\n", a*b);
printf("a / b = %f\n", a/b);
return 0;
}
2. Relational Operators
is equal to ==
is not equal to !=
Greater than >
Less than <
Greater than equal to >=
Less than equal to <=
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a;
int b;
a = 3;
b = 3;
printf("a + b = %d\n",a==b);
printf("a - b = %d\n",a!=b);
printf("a * b = %d\n",a>b);
printf("a / b = %d\n",a<b);
return 0;
}
3. Logical Operators
Logical AND operator.if both the operands are non zero, then then the condition is true && (A && B) = false
Logical OR operator.if any of these two operands are non zero, then then the condition is true || (A || B) = true
Logiacal NOT Operator. it is used to reverse the logical state of its operand. if condition is true, then logical NOT operator make it false ! !(A && B) = false
#include <stdio.h>
int main(int argc, char const *argv[])
{
int a;
int b;
a = 3;
b = 34;
printf("a + b = %d\n",a&&b);
printf("a - b = %d\n",a||b);
printf("a / b = %d\n",!b);
return 0;
}
= Simple assignment operator. Assign values from right side operand to left side operand.
+= Add AND assignment operator. it adds the right operand to the left operand and assign the result of left operand.
-= Subtract AND assignment operator. it subtract the right operand to the left operand and result is assign to the left operand.
/= Divide AND assign operator. it divides the left operand with the right operand and the result is assign to the left.