OA. free
Free
Accenture Core Computer Science Core Computer Science Medium

Q 79.

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 for a=6, b=7, c=5?**

1.
2.  Integer funn(Integer a, Integer b, Integer c)
3.      for(each c from 3 to 5)
4.          b=c^b
5.          a=5+b
6.          a=11+b
7.          a=(a+c)+c
8.      End for
9.      return a+b

Note: ^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

Ops:

Choose one option.
Show answer & explanation
Answer: B. 31

The loop executes three times (c=3,4,5). In each iteration, b is updated via XOR, and a undergoes three assignments (with only the last assignment being retained). Tracing through: after c=3, a=21,b=4; after c=4, a=19,b=0; after c=5, a=26,b=5. The function returns a+b = 26+5 = 31.

Step-by-step Derivation:
Step-by-step execution:

Initial: a=6, b=7, c=5 (c is overwritten in loop)

Iteration 1: c=3

  • b = 3 XOR 7 = 011 XOR 111 = 100 = 4
  • a = 5+4 = 9 (overwritten next line)
  • a = 11+4 = 15 (overwritten next line)
  • a = (15+3)+3 = 21
  • After iteration 1: a=21, b=4

Iteration 2: c=4

  • b = 4 XOR 4 = 0
  • a = 5+0 = 5 (overwritten next line)
  • a = 11+0 = 11 (overwritten next line)
  • a = (11+4)+4 = 19
  • After iteration 2: a=19, b=0

Iteration 3: c=5

  • b = 5 XOR 0 = 5
  • a = 5+5 = 10 (overwritten next line)
  • a = 11+5 = 16 (overwritten next line)
  • a = (16+5)+5 = 26
  • After iteration 3: a=26, b=5

Return: a+b = 26+5 = 31

Wait, let me recalculate more carefully:

Iteration 3 rechecked: c=5

  • b = 5 XOR 0 = 5
  • a = 11+5 = 16
  • a = (16+5)+5 = 26
  • Return: 26+5 = 31

Actually, this gives 31 (Option B). Let me verify the entire trace once more to ensure correctness.

After careful re-execution, the answer is 31, not 39. The trace shows a=26, b=5, and 26+5=31.