Monday, December 7, 2009

2.3 RELATIONAL AND LOGICAL OPERATORS

There are four relation operators in C.They are
< -->less than
<= -->less than or equal to
> -->greater than
>= greater than or equal to

Closely associated with the relation operators are the following two equality operators

== -->equal to
!= -->not equal to

In addition to the relational and equality operators,C contains two logical operators (also called logical collectives).They are

&& -->and
|| -->or

The result of logical and operation will be true only if both operands are true,whereas the result of a logical or operation will be if either operand is true or if both operands are true.

e.g.suppose that i is an integer variable whose value is 7,f is a floating point variable whose value is 5.5 and c is a character variable that represents the character 'w'.Several complex logical expressions that make use of these variables are shown below.

Expression----------Interpretation------------Value
(i>=6)&&(c=='w')--------True---------------------- 1
(i>=6)||(c==110)--------True---------------------- 1
(f<11)&&(i>100)---------False---------------------- 0
(c!='p')||((i+f)<=10)----True---------------------- 1

No comments:

Post a Comment