ProgrammingHardTCS NQT · Infosys

Which statement about the standard library function qsort is true?

  1. A. It always keeps elements that compare equal in their original order
  2. B. It returns a newly allocated sorted array and leaves the input unchanged
  3. C. It is guaranteed to be stable whenever the element size is 4 bytes
  4. D. The C standard does not guarantee that elements comparing equal keep their original relative order

Correct answer: D. The C standard does not guarantee that elements comparing equal keep their original relative order

qsort sorts the array in place, and the standard does not require stability. Any implementation may reorder elements that compare equal, so a stable sort needs your own tie-breaker.

More C Programming questions

Exams that ask this topic