ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
int x = 7 / 2 * 2.0;
double y = 7 / 2.0 * 2;
printf("%d %.1f", x, y);
  1. A. 7 7.0
  2. B. 6 7.0
  3. C. 7 6.0
  4. D. 6 6.0

Correct answer: B. 6 7.0

Evaluation is left to right: 7 / 2 is integer division (3) before the 2.0 appears, so x = 6.0, stored as 6. In y, 7 / 2.0 is already 3.5, and 3.5 * 2 = 7.0.

More C Programming questions

Exams that ask this topic