Wednesday, June 25

What are EQUALITY AND LOGICAL OPERATORS


(B) What are equality operators ? well they are used to check the equality of the given expression or a statement. These operator is basically represented by two keys: "equal to" by == operator and "not equal to " by !=. Like relational operators they also produce result either 'true' or 'false' depending on the condition used in the program, for example, a=4, b=6, andc=8 then result of the following expressions would be:
a==b >>>>>>> false
(a*b) != c >>>>> true
's' == 'y' >>>> false

(C) What are logical operators ? Basically logical operators are && and . They are lower in precedence than the relational operators '<''>', which in turn are lower than + and -. The operator && is higher in precedence than the operator . In some other languages, the logical operators are placed higher in precedence than the relational operators, which requires parentheses.
(i) Logical AND : A compound expression is true when two conditions are true. To write both conditions, the operator && is used as
'expression 1 && expression 2'

Situation >> results
(i) true&&true >> true
(ii) true&&false >> false
(iii) false&&true >> false
(iv) false&&false >> false
for example: a=4, b=5 and c=6
(4<5) && (5<6)
(true) && (true)
by rule (i) result is 'true'

(ii) Logical OR : It is represented by , and truth table goes like this....
Situation >> Results
True OR True >> True
True OR False >> True
False OR True >> True
False OR False >> False
(iii) Logical negation operator : There is one more logical operator that is denoted by !. The results are as follows :
Situation Results
!(True) False
!(False) True
The expression is written as :
!(expression)
Negation operator has higher level precedence over && and .... To avoid the confusion between them () parentheses is used whenever necessary......
That's all for the day do come tomorrow for more......

0 comments:

Followers

Archive

 

Money ,Entertainment and Education. Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com