Logical Operators:
C++ provides us the facility of combining logical expression and evaluate their behavior. So, in this C tutorial for beginner, we are going to discuss logical operators in c. We are going to discuss how to form and evaluate logical expressions and see how they work.Below are three logical operators in C++ that we normally use:
Operator Description
- ! not
- && and
- || or
Logical operators in c take two logical values, combine them and finally gives one logical value.
Expression !expression
True (nonzero) false (0)False (0) true (1)
When you put not “ ! ” operator with expression it changes
- True to false
- False to true
- Nonzero to zero
- Zero to one
Let’s see some examples of “not” operator:
- ! (‘B’ > ‘A’) !(true) false
- !( 1 <= 10 ) !(true) false
- !(1 != 1) !(false) true
Let’s see some examples of “and” operator:
- ( 100 >= 101 && 100 <= 101) false
- ( “shapes” == “shapes” && “me” == “me”) true
- (!false && true) true
- (1>0 && 1<0) false
Let’s see some examples of “or” operator:
- ( 100 >= 101|| 100 == 101) false
- ( “shapes” > “shapes” || “me” == “me”) true
- (!false || !true) true
- (1==0 || 1<0) false
Final words:
Logical operators are important in C++ programming. They have been discussed in detail in this c tutorial for beginners.We hope that this post will be help full for our viewers.