RELATIONAL OPERATORS:
- Relational operators are used to compare two operands.
- Result is either a TRUE or FALSE value.
- The value of TRUE is 1(non zero) and the value of FALSE is 0(zero).
OPERATOR < > <= >= == != | MEANING Less Than Greater Than Less Than or equal to Greater Than or equal to Equal to Not Equal to | PRECEDENCE 1 1 1 1 2 2 |
If W=7 X=5 Y=10 Z=7
- X<Y TRUE (Value 1)
- W==Z TRUE (Value 1)
- Z>Y FALSE (Value 0)
- W!=X TRUE (Value 1)
LOGICAL OPERATORS:
- AND,OR and NOT are three Logical Operators.
- The result of these operators is either TRUE or FALSE.
- AND,OR are Binary operators.
- NOT is Unary Operator.
OPERATOR && || ! | MEANING Logic AND Logic OR Logic NOT | PRECEDENCE 2 3 1 |
KEY POINTS ABOUT TABLE:
- AND Operator is Equivalent to Multiplication.
- OR Operator is Equivalent to Addition.
- The result of Logic ANDing is TRUE when both the operands are TRUE otherwise FALSE.
- The result of Logic ORing is FALSE when both the operands are FALSE otherwise TRUE.
- The result of Logic NOT is TRUE when the Operand is FALSE and vice versa.
UNARY OPERATORS:
Unary operators acts upon only one operand. They are of 3 types:
- Unary minus
- Logical NOT operator
- Bitwise complement
1) Unary Minus:
If x=2 and y=5
z = x + (-y)
= 2 + (-5)
= -3
Value of z is -3 because initially y is positive integer variable, when operated by unary minus, its value changed to negative.
2) Logical NOT operator:
3) Bitwise complement:
Let a=10 and is equivalent to 1010 Binary value
z = ~a
=~(1010)
= 0101
z = x + (-y)
= 2 + (-5)
= -3
Value of z is -3 because initially y is positive integer variable, when operated by unary minus, its value changed to negative.
2) Logical NOT operator:
OPERAND True False | !OPERAND False True |
3) Bitwise complement:
Let a=10 and is equivalent to 1010 Binary value
z = ~a
=~(1010)
= 0101
0 Response to "Detailed Discription of C Language Operators section-2"
Post a Comment