(4 < 8 ) && (12 <= 40 ) && (50 > 1)
is true
An expression with two &&
operators
works like you expect.
But let us look at the situation in detail.
When the &&
operator is used twice in
an expression, group the first &&
and its
operands together like this:
(4 < 8 ) && (12 <= 40 ) && (50 > 1)
is equivalent to:
( (4 < 8 ) && (12 <= 40 )) && (50 > 1)
Evaluate that first group.
The result is true
or false
.
Now use that value with the next &&
operator:
( true ) && (50 > 1)
( true ) && true
true
The effect of this is that for the entire expression to
be true
, every operand must be true
.
Short-circuit evaluation is still going on, so
the first false
value stops evaluation and
causes the entire expression to be false
.
What is the value of:
(4 < 8 ) && ( 8 < 0 ) && ( 100 > 45 )