Logical Operators

Default Image

Logical operators are used to generate
more complex conditions for our programme. When we require to verify
several conditions then we use logical operators. To build a logical
condition we need two or more relational expressions. There are three
types of logical operators available in C++ that are given below:

  • AND (&&)
  • OR (||)
  • NOT (!)

1.1.1      AND operator


              AND operator is denoted by
double ampersand sign (&&). It is used to evaluate tow or more
than two relational expressions and returns true if all of them stands
true and returns false if any of them is false. For example, if a=3,
b=6, c=3, d=2 then


  • (ad) returns true
  • (ac) returns false

1.1.2      OR operator


               OR operator is denoted by
double pipe sign (||). It is used to evaluate two or more than two
relational expressions and returns true if any of them stands true and
returns false if all of them is false. For example, if a=3, b=6, c=3,
d=2 then


  • (a>d)||(a>b) returns true
  • (ac) returns false

1.1.3      NOT operator


              NOT operator is denoted by
single exclamation sign (!). It is used to evaluate single relational
expression and it returns the exact opposite of the expression result.
If relational expression is true then it will return false and if
expression is false it will return true after the use of NOT operator.
For example, if a=3, b=6, c=3, d=2 then


  • a>d returns true and !(a>d) returns false
  • a

Read Count: 3 times

Comments

No comments yet.

Leave a Comment