Compound Boolean Expressions

AP Computer Science A· difficulty 3/5

int x = 5;
if (x > 0 || x++ > 100) {
  System.out.println(x);
}

What is printed?

  • A

    5

    check_circle
  • B

    6

  • C

    0

  • D

    100

Explanation

Short-circuit ||: x > 0 is true (5 > 0), so the right-hand expression x++ is NOT evaluated. x remains 5.

Want 10 more like this — adaptive to your weak spots?

Related questions