Showing posts with label or operator in c. Show all posts
Showing posts with label or operator in c. Show all posts

Sunday, 6 October 2013

Logical Operators

 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

  1. !                    not
  2. &&                and
  3. ||                    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
  1. True to false
  2. False to true
  3. Nonzero to zero
  4. Zero to one

Let’s see some examples of “not” operator:

  1. ! (‘B’ > ‘A’)          !(true)             false
  2. !( 1 <= 10 )        !(true)             false
  3. !(1 != 1)            !(false)             true

Let’s see some examples of “and” operator:

  1. ( 100 >= 101 && 100 <= 101)                          false
  2. ( “shapes” == “shapes” && “me” == “me”)        true
  3. (!false && true)                                                true
  4. (1>0 && 1<0)                                                   false

Let’s see some examples of “or” operator:

  1. ( 100 >= 101|| 100 == 101)                             false
  2. ( “shapes” > “shapes” || “me” == “me”)            true
  3. (!false || !true)                                                true
  4. (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.