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

Q 63.

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 pp,qq,rr
2.  Set pp=5, qq=6, rr=4
3.  if((pp+5)>(qq-pp))
4.    pp=(8+11)&pp
5.    rr=(7+9)+rr
6.  End if
7.  pp=pp&rr
8.  Print pp+qq+rr

Note - & bitwise AND - The bitwise AND operator (&) compares each bit of the first operand to the corresponding bit of the second operand. If both bits are 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.

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

The if condition (pp+5)>(qq-pp) evaluates to (5+5)>(6-5) = 10>1 = true, so the if block executes. pp=(8+11)&pp = 19&5 = 17 (in binary: 10011 & 00101 = 00001 = 1). Then rr=(7+9)+rr = 16+4 = 20. After the if block, pp=pp&rr = 1&20 = 0. Finally, pp+qq+rr = 0+6+20 = 26.

Step-by-step Derivation:
Step 1: Initialize pp=5, qq=6, rr=4
Step 2: Evaluate if condition: (pp+5)>(qq-pp) = (5+5)>(6-5) = 10>1 = true
Step 3: Execute if block

  • pp = (8+11)&pp = 19&5
    Binary: 19 = 10011, 5 = 00101
    19&5 = 10011 & 00101 = 00001 = 1
    pp = 1
  • rr = (7+9)+rr = 16+4 = 20
    rr = 20
    Step 4: pp = pp&rr = 1&20
    Binary: 1 = 00001, 20 = 10100
    1&20 = 00001 & 10100 = 00000 = 0
    pp = 0
    Step 5: Print pp+qq+rr = 0+6+20 = 26