logical operators

In this blog
logical operators


logical operators


 operator meaning   
      &&logical and
         ||
 logical or
        !logical not



logical and (&&)

Truth table of logical and
 A BA&&b 
 0 0 
 010
 10 0 
 11

if both the operand are true only then A&&b would be 1

eg

printf("%d", A&&B) // A=2 ,B=3                                            output would be 1

(note: if the left operand is false in this case A then it would not check for the right operand if it is true or not ,B in this case )

logical or ( || )

Truth table of logical or
 A BA||b 
 0 0 
 011
 10 1 
 11

if one of the operand is true then the result of A || b would be true 

eg 

printf("%d", A||B)// A=2 ,B=0                                                                                output would be 1

(note: if the left operand is true in this case A then it would not check for the right operand if it is true or not ,B in this case )


logical not ( ! )

Truth table of logical not
 A !A
 01
 1 0 

logical not reverse the output , if it is true then it is reverse to false or vice versa.

eg

printf("%d", !A) // A=1                                                                                      output would be 0

back to top

No comments:

Post a Comment

Contact Form

Name

Email *

Message *