ProgrammingHardInfosys · Wipro pattern

What will be the output of the following pseudocode? (&& binds more tightly than ||; ! is NOT.)

What will be the output of the following pseudocode? (&& binds more tightly than ||; ! is NOT.)
Integer a = 5, b = 10, c = 15
if (a > b || b < c && c > 20)
    Print "X"
else if (!(a == 5) || c mod b == 5)
    Print "Y"
else
    Print "Z"
end if
  1. A. Y
  2. B. X
  3. C. Z
  4. D. XY

Correct answer: A. Y

First condition: a > b is false, and b < c && c > 20 is true && false = false, so the whole || is false. Second: !(a == 5) is false, but 15 mod 10 = 5 is true → 'Y'. Dropping the && part and testing only a > b || b < c would wrongly print 'X'.

More Pseudocode and Code Tracing questions

Exams that ask this topic