![]() |
VOOZH | about |
In this article, we will see what is Boolean Expression.
Before starting with the topic directly lets us see what is a Boolean expression. 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 and vice versa.
Let's take one simple example that will clear the concept of Boolean expression so the expression (5>2) i.e. 5 greater than 2 as we can see it is true that means 5 is greater than 2 therefore the result will be true as we can see the expression yields true as value, therefore, it is called Boolean expression.
When more than two expressions are to be evaluated (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 are used to connecting more than 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.
Examples: let's check if 5 is greater than 2 and less than 10 using boolean operators and expressions so in programming they will be written like (5>2&&5<10), as we want both expressions to be evaluated as true so we used AND so the result of this boolean expression will be true as 5, is greater than 2 and it is less than 10, therefore, it will produce GFG! as output in the program given below also various examples are included in it.
Time Complexity: O(1)
Auxiliary Space: O(1)
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 increase.