ProgrammingEasyTCS NQT · Wipro pattern
What will be the output of the following pseudocode? (/ is integer division.)
What will be the output of the following pseudocode? (/ is integer division.)
Integer x = 10 x = x + x * 2 - 4 / 2 Print x
- A. 18
- B. 38
- C. 20
- D. 28
Correct answer: D. 28
* and / first: x * 2 = 20 and 4 / 2 = 2. Then left to right: 10 + 20 − 2 = 28. Evaluating strictly left to right ((10 + 10) * 2 − 4) / 2 = 18 ignores precedence.
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? for (i = 10; i >= 1; i = i - 3) Print i end for
- What will be the output of the following pseudocode? (/ is integer division; + on strings concatenates.) Integer n = 100 String s = ""…
- What will be the output of the following pseudocode? (/ is integer division.) Function f(Integer n) if (n == 0) return 0 end if return (n…
- What will be the output of the following pseudocode? (/ is integer division.) Integer n = 25, z = 0 while (n > 0) n = n / 5 z = z + n end…
- What will be the output of the following pseudocode? Integer s = 0 for (i = 1 to 30) if (i mod 4 == 0) continue end if if (i mod 7 == 0)…
- What will be the output of the following pseudocode? (Byte variables are 8-bit unsigned: they hold 0–255 and arithmetic wraps modulo 256.)…