ProgrammingModerateTCS NQT · Infosys

c is a char holding '5'. What is printf("%d", (c - '0') * 2)?

  1. A. 5
  2. B. 53
  3. C. 106
  4. D. 10

Correct answer: D. 10

c - '0' is 5 because the digit characters are contiguous in every conforming character set, and 5 * 2 = 10. Subtracting '0' first is the standard way to read a digit.

More C Programming questions

Exams that ask this topic