Pseudo-code questions and answers

Trace loops, recursion and bitwise logic. Practise pseudo-code questions from the technical & programming section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample pseudo-code questions with worked answers

Question 1

What will be the output of the following pseudocode?

Integer a, b
Set a = 15, b = 4
a = a + b
b = a - b
a = a - b
Print a, b
  1. 15 4
  2. 19 15
  3. 4 15
  4. 4 4

Answer: C. 4 15

Explanation: a becomes 19, then b = 19 - 4 = 15, then a = 19 - 15 = 4. The values are swapped without a temporary variable.

Question 2

What will be the output of the following pseudocode? (Note: &, | and ^ are bitwise AND, OR and XOR.)

Integer a, b, c
Set a = 12, b = 7
c = a ^ b
a = c ^ a
Print a + c
  1. 23
  2. 18
  3. 19
  4. 11

Answer: B. 18

Explanation: c = 12 ^ 7 = 1100 ^ 0111 = 1011 = 11. Then a = 11 ^ 12 = 1011 ^ 1100 = 0111 = 7. a + c = 7 + 11 = 18.

Question 3

What will be the output of the following pseudocode?

Integer fun(Integer n)
    if (n < 3)
        return n
    end if
    return fun(n - 1) + fun(n - 3)
End function fun()

Print fun(7)
  1. 7
  2. 13
  3. 10
  4. 9

Answer: C. 10

Explanation: fun(0) = 0, fun(1) = 1, fun(2) = 2. Then fun(3) = 2 + 0 = 2, fun(4) = 2 + 1 = 3, fun(5) = 3 + 2 = 5, fun(6) = 5 + 2 = 7 and fun(7) = 7 + 3 = 10.

All 30 pseudo-code questions with answers

Pseudo-code: common questions

What are pseudo-code questions?

Trace loops, recursion and bitwise logic. They appear in the technical & programming section of many placement tests.

Where can I practise pseudo-code questions with answers for free?

Right here on LogicWiz Exams. Every pseudo-code question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise pseudo-code?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of pseudo-code questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: Technical & Programming practice.

More technical & programming topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep