ProgrammingModerateAccenture · Capgemini

What will be the output of the following pseudocode? (c ? x : y evaluates x if c is true, otherwise y)

What will be the output of the following pseudocode? (c ? x : y evaluates x if c is true, otherwise y)
Integer marks[6] = {92, 75, 60, 88, 45, 75}
Integer A = 0, Bc = 0, C = 0
for (each i from 0 to 5)
    Integer m = marks[i]
    m >= 85 ? (A = A + 1) : (m >= 70 ? (Bc = Bc + 1) : (C = C + 1))
end for
Print A, Bc, C
  1. A. 2 3 1
  2. B. 1 2 3
  3. C. 3 2 1
  4. D. 2 2 2

Correct answer: D. 2 2 2

The nested conditional checks ≥ 85 first, then ≥ 70: 92 and 88 → A; 75 and 75 → B; 60 and 45 → C. Output 2 2 2.

More Pseudocode and Code Tracing questions

Exams that ask this topic