ProgrammingHardCapgemini · Cognizant GenC Next

What will be the output of the following pseudocode? (AND has higher precedence than OR)

What will be the output of the following pseudocode? (AND has higher precedence than OR)
Integer a = 5, b = 2, c = 3
if (a > b OR b > c AND c > a)
    Print a + b + c
else
    Print a - b - c
end if
  1. A. 0
  2. B. 30
  3. C. 7
  4. D. 10

Correct answer: D. 10

AND binds tighter than OR, so the test is (a > b) OR (b > c AND c > a) = true OR false = true, and 10 is printed. Reading it left to right as (a > b OR b > c) AND c > a gives false and the trap 0.

More Pseudocode and Code Tracing questions

Exams that ask this topic