Simple Logical Operators Example Program In C++

Read About C++ Operators

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