ProgrammingVery hardProduct company OA

What is printed?

What is printed?
printf("%.1f", 1 ? 3 : 2.5);
  1. A. 2.5
  2. B. 3
  3. C. Undefined: an int is passed for %f
  4. D. 3.0

Correct answer: D. 3.0

The second and third operands of ?: are brought to a common type by the usual arithmetic conversions, so the expression has type double even though the int branch is chosen. printf receives 3.0 and prints it with one decimal.

More C Programming questions

Exams that ask this topic