ProgrammingHardProduct company OA

Assume ASCII. What does f("Code21") print?

Assume ASCII. What does f("Code21") print?
void f(const char *s) {
    if (*s) {
        f(s + 1);
        if (*s % 2) putchar(*s);
    }
}
  1. A. 1eC
  2. B. 1eoC
  3. C. Coe1
  4. D. Ceo1

Correct answer: B. 1eoC

The print happens after the recursive call, so characters come out in reverse. Only odd character codes print: 'C' 67, 'o' 111, 'e' 101 and '1' 49 are odd; 'd' 100 and '2' 50 are even. Reversed: 1, e, o, C.

More C Programming questions

Exams that ask this topic