Question discussion

What is the output of the following C program?#include void f(int n) { if (n == 0) return; printf("%d", n % 2); f(n / 2); } int main() { f(…

1118Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
void f(int n) {
    if (n == 0) return;
    printf("%d", n % 2);
    f(n / 2);
}
int main() { f(13); return 0; }
  • A1011
  • B1101
  • C1110
  • D0111
Correct answer: A

Explanation

The remainders printed in order for 13, 6, 3, 1 are 1, 0, 1, 1, i.e. 1011 (the binary of 13 in reverse).

Discussion 0

Nobody has replied yet. Start the discussion!