ProgrammingHardGATE CS · Campus placements

qsort is called on int arr[5] = {-7, 3, -2, 5, -4} with a comparator that returns (abs(a) > abs(b)) - (abs(a) < abs(b)) on the two elements. What is the resulting order?

  1. A. -2 3 -4 5 -7
  2. B. -7 -4 -2 3 5
  3. C. 3 -2 -4 5 -7
  4. D. -2 -4 3 5 -7

Correct answer: A. -2 3 -4 5 -7

The comparator orders by absolute value only. The absolute values 2, 3, 4, 5, 7 are all distinct, so the ascending result is -2, 3, -4, 5, -7.

More C Programming questions

Exams that ask this topic