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
- A.
5
- B.
3
- C.
2
- 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):
Compute (x AND y): x = 2 (true), y = 1 (true), so (x AND y) is true (1).
Compute (z + 1): z = 5, so z + 1 = 6.
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.