ProgrammingHardTCS NQT · Infosys

int a[] = {3, 1, 2}; qsort(a, 3, sizeof(int), cmp) sorts ascending, where cmp compares with (x > y) - (x < y). Then What is a[0]*100 + a[1]*10 + a[2]?

  1. A. 321
  2. B. 123
  3. C. 132
  4. D. 213

Correct answer: B. 123

After sorting the array is {1, 2, 3}, so the value is 100 + 20 + 3 = 123. The comparator returns a value of the correct sign for every pair of ints.

More C Programming questions

Exams that ask this topic