ProgrammingHardTCS NQT · Infosys

int n = 5; int r = n++ * 2; What are the final values of r and n?

  1. A. r = 10, n = 6
  2. B. r = 12, n = 6
  3. C. r = 10, n = 5
  4. D. r = 12, n = 5

Correct answer: A. r = 10, n = 6

n++ yields the old value 5, so r is 10, and n is incremented to 6. The side effect is applied once with no conflicting read, so the code is well defined.

More C Programming questions

Exams that ask this topic