ProgrammingHardTCS NQT Advanced · Accenture
What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)
What will be the output of the following pseudocode? (ref means the argument is passed by reference; other parameters are copies)
Procedure upd(Integer a, ref Integer b)
a = a + b
b = a * 2
End Procedure
Integer x = 3, y = 4
upd(x, y)
upd(y, x)
Print x, y- A. 34 14
- B. 3 4
- C. 42 21
- D. 7 14
Correct answer: A. 34 14
First call: a = 3 + 4 = 7 and y (by reference) = 14. Second call: a is a copy of y = 14, a = 14 + 3 = 17, and x (by reference) = 34. Output 34 14.
Practise more Pseudocode and Code Tracing questionsPseudocode and Code Tracing: notes and key points
More Pseudocode and Code Tracing questions
- What will be the output of the following pseudocode? (/ is integer division) Stack st = empty for each token t in "6 2 3 + - 3 8 2 / + "…
- What will be the output of the following pseudocode? Integer a = 144, b = 89, t, steps = 0 while (b != 0) t = a mod b a = b b = t steps =…
- What will be the output of the following pseudocode? (All variables are integers, so / is integer division; , / and mod have equal…
- What will be the output of the following pseudocode? (& is bitwise AND, >> is right shift) Integer s = 0, x, t for (each i from 1 to 16) x…
- What will be the output of the following pseudocode? Integer m[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} for (each i from 0 to 2) for…
- What will be the output of the following pseudocode? Integer n = 0, c = 0 do c = c + 1 n = n + 3 while (n mod 5 != 0) Print c, n