Boolean search

• Last Updated : 02 Dec, 2021

Before starting with the topic directly lets us see what is Boolean expression so It is an expression that always yields two values either true or false when evaluated. If the condition is true then it will return true or false vice versa.

Lets take one simple example that will clear the concept of Boolean expression so the expression (5>2) i.e. 5 greater then 2 as we can see it is true that means 5 is greater then 2 therefore the result will be true as we can see the expression yields true as value therefore it is called Boolean expression.

Need of Boolean Operators :
When more then two expressions are to be evaluated  like (expression 1,expression 2) so it is done using boolean operators so we need to connect them using Boolean operators like (expression 1,boolean operator, expression 2)

Boolean Operators :
Boolean operators are used to connect more then two expressions so that they will be evaluated. When you want multiple expressions to be evaluated then we use Boolean operators and using that multiple expressions are evaluated and we get the answer as true or false

Types of Boolean Operators :

• AND in most of time it can be used as AND or it depends on programming language like in C CPP programming it is represented as &&
• OR in most of time it can be used as OE or it also depends  on programming language like in  C CPP programming it is represented as ||
• NOT also is represented as NOT or depends like in C CPP programming is represented as ! (exclamation mark)

Uses of Boolean operators :

• AND operator is used when you want both expressions to be evaluated as true.
• OR operator is used when you want either any one of the two expression should be evaluated as true.

Applications of Boolean expressions :

• Boolean Expressions are used in programming concepts like in if else condition, switch cases etc.
• It is used in Boolean algebra, digital logic and design.

Examples- lets check if 5 is greater then 2 and less then 10 using boolean operators and expressions so in programming they will be written like (5>2&&5<10) as we want both expression to be evaluated as true so we used AND so the result of this boolean expression will be true as 5 is greater then 2 and it is less then 10 therefore it will produce GFG! as output in the program given below also various examples are included in it.

C++

 #include using namespace std; int main(){     if (5 > 2&&5<10)  //checking if 5 is greater then 2 and 5 less then 10        cout << "GFG!";    else        cout << "GeeksforGeeks";    return 0;}

C

 #include  int main(){     if (5 > 2||5<1)  //checking if 5 is greater then 2 or 5 less then 1        printf("GFG!");    else        printf("GeeksforGeeks");     return 0;}

Java

 /*package whatever //do not write package name here */ import java.io.*; class GFG {    public static void main(String[] args)    {         if (5 > 6&&5<10)  //checking if 5 is greater then 6 and less then 10            System.out.println("GFG!");        else            System.out.println("GeeksforGeeks");    }}

C#

 // C# program for the above approachusing System; class GFG{ // Driver Codepublic static void Main(){    if (5 > 6&&5<10)  //checking if 5 is greater then 6 and less then 10        Console.Write("GFG!");    else        Console.Write("GeeksforGeeks");}} // This code is contributed by sanjoy_62.

C++14

 #include using namespace std; int main(){     if (5 > 2&&5<10)   //checking if 5 is greater then 2 and less then 10        cout << "GFG!";    else        cout << "GeeksforGeeks";    return 0;}

Javascript



Boolean expressions are used in many domains like programming and digital logic as it makes the task and logic clear as a result the program efficiency and readability increases.

My Personal Notes arrow_drop_up