What will be the output of the following pseudo code?
Accenture technical mcq question, verified with a worked answer. Free to practise - no sign-up.
What will be the output of the following pseudo code?
1 Integer: p, q, r
2 Set p = 6, q = 5, r = 10
3 if ((p & q & r) < (6 - r - p))
4 r = (p & q) ^ p
5 End if
6 Print p + q + r
Show answer & explanation
The condition evaluates to false (4 < -9 is false), so the assignment inside the if block does not execute. Therefore, r remains 10, and the final output is p + q + r = 6 + 5 + 10 = 21.
Step-by-step Derivation:
Step 1: Initialize p = 6, q = 5, r = 10
Step 2: Evaluate the condition (p & q & r) < (6 - r - p)
Left side: p & q & r
p = 6 = 0110 (binary)
q = 5 = 0101 (binary)
r = 10 = 1010 (binary)
p & q = 0110 & 0101 = 0100 = 4
4 & r = 0100 & 1010 = 0000 = 0
Right side: 6 - r - p = 6 - 10 - 6 = -10
Condition: 0 < -10 → FALSE
Step 3: Since the condition is false, the if block is skipped. r remains 10.
Step 4: Print p + q + r = 6 + 5 + 10 = 21