What will be the output of the following pseudo code? Integer x, y, z, a Set x…

2025

What will be the output of the following pseudo code?

Integer x, y, z, a

Set x = 2, y = 1, z = 5

a = (x AND y) OR (z + 1)

Print a

  1. A.

    5

  2. B.

    3

  3. C.

    2

  4. D.

    1

Attempted by 23 students.

Show answer & explanation

Correct answer: D

Correct Answer: 1

Explanation: Evaluate the expression step by step using logical operators (any non-zero integer is treated as true):

  1. Compute (x AND y): x = 2 (true), y = 1 (true), so (x AND y) is true (1).

  2. Compute (z + 1): z = 5, so z + 1 = 6.

  3. Compute (x AND y) OR (z + 1): true OR 6 evaluates to true (1) because logical OR short-circuits once it finds a true operand.

Therefore a = 1.

Note: If AND and OR were intended as bitwise operators, the result would differ: (2 & 1) = 0 and 0 | 6 = 6. The available choices indicate the expression is using logical operators, so the correct result is 1.

Explore the full course: Infosys Preparation