go to previous page   go to home page   hear noise   go to next page

Answer:

(4 < 8 ) && (  8 < 0 ) && ( 100 > 45 )
   (T    &&      F)    && ( 100 > 45 )
          F            && ( 100 > 45 )

... evaluation stops with the value false for the entire expression.

Cascade of && Operators

When there are more than two && operators in an expression, pairs of operands are grouped togther with an && starting from the left and going toward the right of the expression. Such a group works as a single operand for the next && to the right.

Assume that V, W, X, Y, and Z stand for boolean operands. Then operands are grouped from left to right:

   V && W  && X   && Y  && Z

  (V && W) && X   && Y  && Z

 ((V && W) && X ) && Y  && Z

(((V && W) && X ) && Y) && Z

In the last line (above) every && operator has one operand to its left and one operand to its right. The associativity of an operator is how its operands are grouped in situations like this. The && operator has Left to Right Associativity. Most (but not all) operators work this way.

If you are not happy with the above discussion, don't worry about it. Mostly all you need to know is that an expression with many &&'s works by looking for a false starting from the left and going toward the right. The first false it finds stops evaluation and causes the entire expression to be false. If every operand is true then every operand is evaluated and the entire expression is true.

QUESTION 10:

What is the value of:

(4 < 8 ) || (  8 < 0 ) || ( 100 > 45 )