Section 5 : Operators and Assignments
In an expression involving the
operators &, |, &&, ||, and variables of known values
state which operands are evaluated and the value of
the expression.
Let us take an
expression :
(expression1 op expression2);
where op is any one of
the above operators and the two operands are boolean
expressions.
The operators && and ||
are known as short cut logical operators. In the above
expression, if op is one of these operators then there
may be instances when only the first expression will
be evaluated and not the second expression. If the
evaluation of the first expression itself determines
the result of the overall expression, then the second
or right hand expression will not be evaluated.
For example, if the
operator is && and if the first expression evaluates
to false, then it is clear that whatever the result of
evaluating the right hand expression, the overall
expression will evaluate to false only. In such cases,
there is no need to evaluate the second expression.
But, if the first expression evaluates to true, then
the overall result of the complete expression will
depend on the second expression. In such cases, the
second expression will be evaluated.
Operators & and | always
evaluate both the operands.
section5-1-1 | section5-1-2 | section5-2 | section5-3 | section5-4
Sections :
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
|