The expression evaluates to False.
One way to show this is below.
Assume that x
contains 9 and y
contains 7.
x<12 && y>10 9<12 && 7>10 --+-- --+-- | | T F ---+----- | F
A truth table is another way to show the evaluation of a boolean expression. The first several columns in a truth table show all possible truth values of the operands. The other columns show the truth value of subexpressions containing the operands.
The table below shows two operands in its first two columns.
Each operand can be true or false,
so there are four possible combinations of values
and four rows in the table.
The last column shows the output of the
&&
operator
with those values.
x < 12 | y > 10 | x < 12 && y > 10 |
---|---|---|
F | F | F |
F | T | F |
T | F | F |
T | T | T |
Each row of the truth table shows one possible set of conditions.
For example, if x
contains 9 and y
contains 7
then the third row of the table is selected.
What row of the table is used when x
contains 1 and y
contains 23?