ProgrammingHardTCS NQT · Infosys
void rev(char *s) { char *e = s + strlen(s) - 1; while (s < e) { char t = *s; *s++ = *e; *e-- = t; } } After rev("abcde") runs on a writable array, what is the third character?
- A. a
- B. b
- C. c
- D. d
Correct answer: C. c
Reversing "abcde" gives "edcba", whose third character is c. The loop swaps the two ends and moves inward.
More C Programming questions
- Which algorithm finds the maximum subarray sum of an array of n = 10^6 ints in time within a typical 1 second contest limit?
- char s = "hello"; What is strlen(s + 2)?
- int x = 1, y = 2, z = 3; int ptrs[3] = {&x, &y, &z}; What is ptrs[1] + ptrs[2]?
- printf("%d", 0x7FFFFFFF == 2147483647); What is printed?
- unsigned char c = 0xFF; unsigned int u = c << 8 | c; printf("%X", u); What is printed?
- static int total = 0; int add(int n) { static int t = 0; t += n; return t; } Calls add(3), add(4) and add(5) in that order. What does the…