ProgrammingVery hardProduct company OA

What does z("abcdef") print?

What does z("abcdef") print?
void z(const char *s) {
    if (!*s) return;
    putchar(*s);
    z(s + 2);
    if (s[1]) putchar(s[1]);
}
  1. A. acefdb
  2. B. acebdf
  3. C. acefbd
  4. D. abcdef

Correct answer: A. acefdb

Characters at even positions print on the way down: a, c, e. The odd-position partner of each level prints on the way back up, innermost first: f, d, b. So acefdb.

More C Programming questions

Exams that ask this topic