Logical operator in C++
Basically local operators have two types.
No 1:OR operator (||)
No 2:And operator (&&)
OR operator (||) It is use to define two or more than two condition in a single line and if one of them is true than the program will be executed otherwise not
For example
int a=30;
int b=40;
int c=20;
if (a>b||a>c)
cout<<"a is the greater than c or a is greater than b"<<endl;
Example #include<iostream.h>
int main()
{
int a=2;
int b=3;
int c=4;
if(a>b||a>c)
cout<<"a is greater than b OR a is greater than c" <<endl;
if(b>a||b>c)
cout<<"b is greater than a OR b is greater than c" <<endl;
if(c>b||c>a)
cout<<"c is greater than b OR c is greater than a" <<endl;
system("pause");
return 0;
};
AND operator (&&)It is use to define two or more than two condition in a single line and if all the condition is true than the program will be executed otherwise not. For example
int English =30;
int Urdu=67;
if(English>33 && Urdu>33)
cout<<"you are passed in all subjects"<<endl;
Example #include<iostream.h>
int main()
{
int a=2;
int b=3;
int c=4;
if(a>b||a>c)
cout<<"a is the greatest number among these"<<endl;
if(b>a||b>c)
cout<<"b is the greatest number among these"<<endl;
if(c>b||c>a)
cout<<"c is the greatest number among these"<<endl;
system("pause");
return 0;
};