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);
}- A. 1101
- B. 1011
- C. 0111
- 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
- What is printed? Assume uint16t is 16 bits. c #include <stdint.h> #include <stdio.h> int main(void) { uint16t a = 300, b = 300; uint32t p…
- What is printed? c #include <stdio.h> #include <stdlib.h> int ds(int n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } int…
- What is printed? c #include <stdio.h> #include <string.h> int main(void) { char names[] = {"x", "yy", "zzz"}; char pp = names + 1…
- What is printed? c #include <stdio.h> int main(void) { int a[3] = {1, 2, 3}, b[3] = {4, 5, 6}; int ptr[2] = {a, b}; int (pa)[3] = &b…
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 37; printf("%u", n ^ (n >> 1)); }
- What is printed? c #include <stdio.h> int main(void) { int x = -8; printf("%d", x / 2 + x % 3); }