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]?
- A. 321
- B. 123
- C. 132
- 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
- A program must answer 10^5 range-sum queries on an array of 10^5 ints within a 1 second limit. Which approach is fast enough?
- Using fast exponentiation with reduction modulo 1000000007 after each multiplication, what is 2^100 mod 1000000007?
- int n = -1; uint64t u = (uint64t)n; What is u?
- uint32t fib(int n) iteratively computes a = 0, b = 1, then n times: t = a + b; a = b; b = t, with all arithmetic in uint32t. What is…
- int x = 5; x = x++; What is the outcome of this statement?
- uint16t h = 0; for each character c of "ABCDE", h = h 31 + c; with 65 for 'A' and so on. What is h at the end?