ProgrammingHardTCS NQT Advanced · Accenture
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Procedure upd(Integer arr[], Integer n) // arrays are passed by reference
arr[0] = arr[0] + n
n = n * 2
arr[1] = arr[1] + n
End Procedure
Integer a[2] = {1, 1}, k = 3
upd(a, k)
upd(a, k)
Print a[0], a[1], k- A. 7 13 12
- B. 4 7 3
- C. 7 25 12
- D. 7 13 3
Correct answer: D. 7 13 3
The array is shared, but n is a copy, so k stays 3. Each call adds 3 to a[0] and 6 to a[1]: after two calls a = {7, 13}. Output 7 13 3.
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 bitwise AND) Integer x = 255, y = 256, c1 = 0, c2 = 0 while (x > 0) x = x & (x…
- What will be the output of the following pseudocode? Integer cnt = 0 Procedure go(Integer i, Integer s) if (s == 10) cnt = cnt + 1 return…
- What will be the output of the following pseudocode? Function G(Integer n) if (n == 0) return 0 end if return n - G(G(n - 1)) End Function…
- What will be the output of the following pseudocode? (code(c) gives a letter's character code; 'A' to 'Z' have consecutive codes) String w…
- What will be the output of the following pseudocode? (stop ends the program; arrays are indexed from 0) Integer a[6] = {3, 4, 5, 6, 1, 8}…
- What will be the output of the following pseudocode? (mod keeps the sign of the dividend (as in C); arrays are indexed from 0) Integer…