ProgrammingModerateTCS NQT · Wipro

What is printed?

What is printed?
#include <stdio.h>
void bits(unsigned n) {
    if (n > 1) bits(n / 2);
    putchar('0' + n % 2);
}
int main(void) {
    bits(11);
}
  1. A. 1101
  2. B. 1011
  3. C. 0111
  4. D. 11

Correct answer: B. 1011

The recursion prints the bits of n from the most significant end, because the call for n / 2 completes before the current digit is printed. 11 is 1011 in binary.

More C Programming questions

Exams that ask this topic