LOGICAL OPERATORS

·

There are two logical operators also available in C.
They are:-
Operator Meaning
&& and
|| or

The result of a logical and operation will be true only if both operands are true where as the result of a logical or operation will be true if either operand is true or if both operands are true. In other words the result of a logical or operation will be false only if both operands are false. Suppose 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 = = 119)

true

1

(f < 11) && (i > 100)

false

0

(c = ‘p‘) || ((i + f) < =

10)

true

1



RELATIONAL AND LOGICAL OPERATORS
These are four relational operators in C.
They are:-

Operator

Meaning

<

Less than

<=

Less than or equal to

>

Greater than

>=

Greater than or equal to



EQUALITY OPERATORS
There are two equality operators in C which are as follows:-

Operators

Meaning

= =

Equal to

! =

Not equal to


The six operators mentioned above are used to form logical expressions representing condi- tions that are either true or false.
The resulting expression will be of type integer, since true is represented by the integer value
1 and false is represented by the value 0.

e.g . Let us suppose i, j and k are integer variables whose values are 1,2 and 3 respectively. Several logical expressions involving these variables are shown below.

Expression

Interpretation

Value




i < j

true

1

(i + j) > = k

true

1

(j + k) > (i + 5)

false

0

k ! = 3

false

0

j = = 2

true

1



About Me

Blog Archive