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

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 one && operator in an expression, pairs of operands are grouped together with an && starting from the left and going toward the right of the expression. Each group works as the left 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 )

go to previous page   go to home page   go to next page