ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 5, b = 0
if (a > 3 && b != 0)
    Print "X"
else if (a > 3 || b > 0)
    Print "Y"
else
    Print "Z"
end if
  1. A. XY
  2. B. Z
  3. C. Y
  4. D. X

Correct answer: C. Y

&& needs both parts true, but b != 0 is false, so X is skipped. || needs only one part true, and a > 3 is true, so Y is printed.

More Pseudocode and Code Tracing questions

Exams that ask this topic