ProgrammingModerateAccenture · Cognizant pattern

What will be the output of the following pseudocode?

What will be the output of the following pseudocode?
Integer a = 5, b, c, d
b = a++            // post-increment
c = ++a            // pre-increment
d = a + b + c
Print a, b, c, d
  1. A. 7 6 7 20
  2. B. 6 5 6 17
  3. C. 7 5 7 19
  4. D. 7 5 6 18

Correct answer: C. 7 5 7 19

b = a++ stores the old value 5 and then makes a = 6. c = ++a first makes a = 7 and stores 7. d = 7 + 5 + 7 = 19.

More Pseudocode and Code Tracing questions

Exams that ask this topic