QuestionQ50

Using Operators and Decision Constructs

Given this code fragment:

Question Image

What is the outcome?

  • A 11
  • B 10
  • C 12
  • D A compile time error occurs.
Explanation

The prefix increment in y = ++x makes both x and y equal to 11. Boolean | does not short-circuit, so the right operand evaluates ++x, increasing x to 12. The condition is true and z receives x, so the printed value is 12.

Community Discussion

No comments yet. Be the first to start the discussion!