ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a, const void *b) {
return *(const unsigned char *)a - *(const unsigned char *)b;
}
int main(void) {
char s[] = "banana";
qsort(s, 6, 1, cmp);
printf("%s", s);
}- A. nnbaaa
- B. abnnaa
- C. aaannb
- D. aaabnn
Correct answer: D. aaabnn
Sorting the bytes ascending puts the three a's first, then b, then the two n's, giving aaabnn.
More C Programming questions
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0xFF & ~0x1Cu; printf("%u", x); }
- What is printed? c #include <stdio.h> int main(void) { unsigned x = 0x0F; x |= 0x40; x &= ~1u; printf("%u", x); }
- What is printed? Assume int is 4 bytes with 4-byte alignment. c #include <stdio.h> union U { char c[5]; int i; }; int main(void) {…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { printf("%d", strcmp("apple", "apricot") < 0); }
- How many times does the letter a occur in "panda"? The program counts with recursion. c #include <stdio.h> int cnt(const char s) { if (s…
- What is printed by this recursive Pascal triangle entry? c #include <stdio.h> int C(int n, int k) { if (k == 0 || k == n) return 1; return…