ProgrammingModerateTCS NQT · Wipro

Assume ASCII. What is printed?

Assume ASCII. What is printed?
int x = 'A' + 1.5;
printf("%c %d", x, x);
  1. A. B 66
  2. B. B 66.5
  3. C. C 67
  4. D. A 65

Correct answer: A. B 66

'A' + 1.5 is computed in double as 66.5; storing it in an int truncates it to 66, which is the code of 'B'. 'C 67' rounds instead of truncating.

More C Programming questions

Exams that ask this topic