GATE Computer ScienceModerateGATE CS (PYQ pattern)

int a = 7, b = 2; float f = a / b + a / 2.0 + (float)(a / b) * b; printf("%.2f %d", f, (int)(a / b * 2.0)); What is printed?

  1. A. 12.50 6
  2. B. 13.50 7
  3. C. 14.00 6
  4. D. 9.50 6

Correct answer: A. 12.50 6

a / b = 3 (integer division); a / 2.0 = 3.5; (float)(a / b) * b = 3 * 2 = 6, so f = 3 + 3.5 + 6 = 12.5. The cast of a / b * 2.0 gives (3 * 2.0) = 6.

More Programming and Data Structures (GATE) questions

Exams that ask this topic