ProgrammingHardProduct company OA

What is printed?

What is printed?
int f(int n) { if (n == 0) return 0; return (n & 1) + f(n >> 1) * 10; }
int main(void) { printf("%d", f(13)); }
  1. A. 111
  2. B. 1011
  3. C. 1101
  4. D. 13

Correct answer: C. 1101

Each call writes the lowest bit as the units digit and shifts the rest one decimal place left, so the binary digits of 13 appear in the right order as a decimal number: 1101. '1011' is the bits read in reverse.

More C Programming questions

Exams that ask this topic