Sunday, February 22, 2009

Logical Operators and Relational Operators


Logical Operators
Logical operators are usually used to convey whether a given condition is true or false.
Since C language does not have data type to convey true and false, C uses a non-zero number as true while false is represented as zero, 0.

There are 3 logical operators: NOT, AND , OR.

The NOT logical operator is denoted as !
The AND logical operator is denoted as &&
The OR logical operator is denoted as ||

The following truth tables clearly explain the usage of the 3 logical operators.
NOT (!)

AND(&&)
As you can see, if either 1 of the condition is false, the whole condition is false.
OR(||)
As you can see, if either 1 of the condition is true the whole condition is true.

No comments: