Saturday, 16 August 2014

Logical Operators

Logical operator:-  C language support three logical operators – logical AND(&&), logical OR( || ),  and logical NOT (!).
Operator
Description
Example
&&
Called Logical AND operator. If both the operands are non-zero, then condition becomes true.
(A && B) is false.
||
Called Logical OR Operator. If any of the two operands is non-zero, then condition becomes true.
(A || B) is true.
!
Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
!(A && B) is true.

Note: - When expression is true, operator returns the value=1
                When expression is false, operator returns the value=0

Truth table for logical AND
A
B
A&&B
0
0
0
0
1
0
1
0
0
1
1
1
                                    For example :-   (a<b)&&(a>b)

Truth table Logical OR
A
B
A||B
0
0
0
0
1
1
1
0
1
1
1
1

Logical NOT (!):- it takes the single expression and negates the value of expression.
Truth table:-
A
!A
0
1
1
0

 For example,    int a =12,b;
                                b=!a;


therefore, the value of b= -12

No comments:

Post a Comment