ProgrammingHardTCS NQT · Infosys · Capgemini
What will be the output of the following pseudocode? (Parameters marked ref are passed by reference; the others by value.)
What will be the output of the following pseudocode? (Parameters marked ref are passed by reference; the others by value.)
Procedure shift(ref a, ref b, c)
Integer t = a
a = b + c
b = t * c
c = a - b
End Procedure
Integer x = 3, y = 4, z = 5
shift(x, y, z)
shift(y, x, z)
Print x, y, z- A. 75 14 5
- B. -90 3 93
- C. 13 100 5
- D. 3 4 5
Correct answer: A. 75 14 5
First call: a=x, b=y: x = 4+5 = 9, y = 3*5 = 15 (c changes only the local copy). Second call: a=y, b=x, t = 15: y = 9+5 = 14, x = 15*5 = 75. z stays 5 throughout because c is by value.
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? (AND has higher precedence than OR, and && style short-circuit evaluation is used…
- What will be the output of the following pseudocode? (^ is bitwise XOR, & is bitwise AND, >> is a right shift; all values are non-negative…
- What will be the output of the following pseudocode? (break leaves only the innermost loop; continue skips to the next iteration of the…
- What will be the output of the following pseudocode? (Arrays are 0-indexed.) Integer a[6] = {4, 7, 1, 9, 3, 6} Integer i = 0 For k = 1 to…
- What will be the output of the following pseudocode? String s = "ABCDEF", r = "" For i = 0 to 5 If i mod 2 = 0 Then r = s[i] + r Else r =…
- What will be the output of the following pseudocode? Integer a = 91, b = 35, steps = 0 While a != b If a > b Then a = a - b Else b = b - a…