ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
int od(unsigned n);
int ev(unsigned n) { return n == 0 ? 1 : od(n - 1); }
int od(unsigned n) { return n == 0 ? 0 : ev(n - 1); }
int main(void) {
    printf("%d %d", ev(10), od(7));
}
  1. A. 1 0
  2. B. 0 0
  3. C. 1 1
  4. D. 0 1

Correct answer: C. 1 1

ev and od call each other on n - 1, so they alternate down to zero. Ten is even, and seven is odd, so ev(10) = 1 and od(7) = 1.

More C Programming questions

Exams that ask this topic