Learn AP Comp Sci

☰

Problem of the Day

Wednesday, October 28, 2026


Problem:

Three students are having a discussion about the order of operations in Boolean logic. One says that && is evaluated before ||, the second states that || is evaluated before &&, and the third says that && and || ) have the same priority and are simply evaluated in order, left to right.

To demonstrate the validity of her statement, one of the students runs a program to evaluate the expression true || true && false, which produces the result true. Which Boolean order of operations is correct?

  1. && is evaluated before ||
  2. || is evaluated before &&
  3. && and || have the same priority, and are evaluated in order, left to right
  4. none of these

Show solution:

The correct answer is a. In the student's example, if the or-statement ( || were evaluated first, either because of its priority or its position as first in the expression, true || true would evaluate as true, and the subsequent and-statement would evaluate to false. This is not the case, so we conclude that the && comparator takes priority over the ||.

To avoid potential confusion in writing complex boolean expressions, liberal use of parentheses is encouraged; expressions enclosed in parentheses always take priority.