Simple Logical Operators Example Program In C++
On this page (10sections)
About this program
This is an example program in c operator example programs. Read the concept first: Arithmetic Operators Example in C++, then study the code and output below.
Logical Operators
- AND, OR operators are used when we want to use two or more Conditions.
Types Of Logical Operators
- && Logical AND
- || Logical OR
- ! Logical NOT
Logical And (&&) Operator
Logical And Operator Definition
If both the operations are successful, then the condition becomes true.
Logical And Operator Syntax
expr1 && expr2
Logical And Operator Syntax Example
if( (a>10) && (a<20) )
printf(?A is in-between of 10 and 20?);
Logical And Operator Example Program
// Header Files
#include<iostream>
#include<conio.h>
//Main Function
using namespace std;
int main ()
{
// Variable Declaration
int num1 = 30,num2 = 40;
//int num1 = 50,num2 = 80;
cout << "Simple Logical Operators Example Program \n";
if(num1>=40 && num2>=40){
printf("Num 1 and Num 2, both are greater than or equal to 40");
}
if(num1>=40 || num2>=40){
printf("Num 1 or Num 2 is greater than or equal to 40");
}
// Wait For Output Screen
getch();
//Main Function return Statement
return 0;
}
Sample Output
Simple Logical Operators Example Program
//if num1 = 30,num2 = 40
Num 1 or Num 2 is greater than or equal to 40
//int num1 = 50,num2 = 80;
Num 1 and Num 2, both are greater than or equal to 40
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.
- Arithmetic Operators Example in C++ — Tutorial — arithmetic, relational and logical operators.
- Simple Relational Operator Example Program In C++ — More in c operator example programs.
- Simple Assignment Operators Example Program In C++ — More in c operator example programs.