What is Operator?
The Operator is a character that represents actions. There are different kinds of operators which perform other activities on given data. Every Operator can’t fulfil every action, and everyone has some restrictions. There are various operators like +(Addition), -(Subtraction), *(multiplication) and /(division). These are the four basic operators we used in our daily calculations. =(Equals to) this is an assignment operator, and many more are used to make the programming simple.
Types of Operators
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Bitwise Operators
- Assignment Operators
- Miscellaneous Operators
Logical Operators
Logical operators work on true or false conditions. Logical operators are symbols or characters which connect two or more expressions, and these operators operate on logical expressions. There are three leading logical operators, Logical AND, Logical OR, and Logical NOT.
- Logical AND : This operator returns true if both the conditions are true.
It is denoted using “&&”.
Example : (14 > 7 && 5<=5), (4 > 3 && 17 >= 7)
- Logical OR : This operator returns true if one of the conditions is true.
It is denoted using “||”.
Example : (25 > 7 || 15 > 7)
- Logical NOT : This is a reverse operator, returns true if the condition is false. It is denoted using “!”.
Example : (9!=7), !false
Example of Logical Operators
/* A program to show various Logical operation */
#include
#include
void main()
{
int a=60,b=30;
int c=10,d=20;
if(a>b && a!=0)
{
printf("&& operator: both conditions are true\n");
}
if(c>d || d!=10)
{
printf("|| operators: only one condition is true \n");
}
if(!(a>b && a !=0))
{
printf("! operator: both conditions are true\n");
} else
{
printf("! operator: both conditions are true."\"but, status is inverted as false");
}
getch();
}
output:
&& operator: both conditions are true
|| operators: only one condition is true
! operator: both conditions are true.
but, status is inverted as false
What is Operator Overloading ?
Operator overloading mechanism is handy, used to create or modify existing operators with some new actions that can’t be performed previously. Specifically, this mechanism is used to perform actions on objects.