ProgrammingHardWipro NLTH · Cognizant GenC
What will be the output of the following pseudocode?
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 1; ++i adds 1 and then gives the new value; operands are evaluated left to right.)
- A. 7 11
- B. 6 12
- C. 7 10
- D. 7 12
Correct answer: D. 7 12
i++ gives 5 (i becomes 6), ++i makes i = 7 and gives 7: j = 12 and i = 7.
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 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…
- What will be the output of the following pseudocode? Integer i, j, c = 0 for (i = 1; i <= 6; i = i + 1) for (j = 1; j <= 6; j = j + 1) if…
- What will be the output of the following pseudocode? Integer a = 48, b = 18, steps = 0 while (a != b) if (a > b) a = a - b else b = b - a…