ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
int score = 73;
char g = score >= 90 ? 'A' : score >= 75 ? 'B' : score >= 60 ? 'C' : 'D';
printf("%c%d", g, g - 'A');
  1. A. C2
  2. B. C3
  3. C. D3
  4. D. B1

Correct answer: A. C2

The conditionals nest to the right and are tested in order: 73 fails ≥ 90 and ≥ 75 and passes ≥ 60, so g = 'C'. 'C' − 'A' = 2 in any character set where the capital letters are consecutive, as in ASCII.

More C Programming questions

Exams that ask this topic