ProgrammingHardGATE CS · Campus placements

A qsort comparator compares double values with (x > y) - (x < y). After sorting {2.5, -1.0, 2.25}, which value is last?

  1. A. -1.0
  2. B. 2.25
  3. C. 2.5
  4. D. 0

Correct answer: C. 2.5

The ascending order is -1.0, 2.25, 2.5, so 2.5 is last. A comparator built from subtraction would also work here, but the three-way form avoids its overflow risk on large values.

More C Programming questions

Exams that ask this topic