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?

  1. A. a
  2. B. b
  3. C. c
  4. 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

Exams that ask this topic