ProgrammingHardTCS NQT · Infosys
What will be the output of the following pseudocode?
What will be the output of the following pseudocode?
Procedure p(Integer a[], Integer x)
a[0] = a[0] + x
x = x + 100
a[1] = x
return x
end procedure
Integer arr[3] = {4, 6, 8}, x = 1, r
r = p(arr, x)
Print arr[0], arr[1], x, r
(Arrays are passed by reference; integers by value.)- A. 5 101 1 101
- B. 5 101 101 101
- C. 5 6 1 101
- D. 5 101 1 1
Correct answer: A. 5 101 1 101
a[0] becomes 5 and the local x becomes 101, so arr[1] = 101; the caller's x stays 1 and r = 101: 5 101 1 101.
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? Integer c = 0 Function inc() c = c + 1 return c end function if (inc() > 0 || inc() >…
- What will be the output of the following pseudocode? Integer i = 5, j j = (i++) + (++i) Print i, j (i++ gives the old value and then adds…
- What will be the output of the following pseudocode? Integer n = 1000, c = 0 while (n != 0) n = n & (n - 1) c = c + 1 end while Print c (&…
- What will be the output of the following pseudocode? Function g(Integer n) if (n == 0) return 0 end if if (n mod 2 == 0) return g(n - 1) +…
- What will be the output of the following pseudocode? Integer a[6] = {1, 2, 3, 4, 5, 6} Procedure rev(Integer l, Integer r) while (l < r)…
- What will be the output of the following pseudocode? String s = "aaabccdddd", r = "" Integer i = 0, j while (i < length(s)) j = i while (j…