Pages

Hello there!

Powered by Blogger.

Monday, January 7, 2013

LOGICAL OPERATORS IN C


LOGICAL OPERATORS IN C WITH EXAMPLE



Operator

.




Meaning
<less than
<=less than or equal to
>greater than
>=greater than or equal to
==equal to
!=not equal to
&&logical AND
||logical OR
!logical NOT

The above 1st 6 are relational operators in java and last 3 are logical operators

The relation operators are used to compare 2 values. The output of relational operators is either true (1) or false (0)

Syntax:-

value1 relational_operator value2


Example:-

2 < 10     True
3 > 8       False
7.5>=5    True

value1 and value2 are can be constants, variable or combination of them.

Relation operator are used in if-else or in loop statement.

Example:-

Program to find Greatest number between 2


Logical operators:-

logical operators && and || are used to when we want to check 2 or more condition statement.

Example

8 > 7 && 5 < 8      True
8 < 5 || 8 < 9           False
7 > 2 && 19 < 2    False

AND (&&) operator output is true only when either condition statement is true.
OR (||) operator output is false only when either condition statement is false.

Truth table:-


ABAND
000
010
100
111


ABOR
000
011
101
111



NOT (!)  logical operator is used for compliment condition statement outputs.

Truth table:-

ANOT
01
10


Example:-

Program to solve following problem
The candidate is selected if his age and height is 18 and 5 and more respectively.



Java program for logical NOT
Program to find max number between 2


0 comments:

Post a Comment