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)); }- A. 111
- B. 1011
- C. 1101
- 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
- What is printed? c struct S { int a; int b; } s[] = {{1, 10}, {2, 20}, {3, 30}}; struct S p = s; int x = ++p->a; int y = (++p)->b; int z =…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0x12345678; printf("%X", (x >> 16) | (x << 16));
- What is printed? c int ok(const char s, int d) { if (d < 0) return 0; if (!s) return d == 0; return ok(s + 1, d + (s == '(') - (s ==…
- What is printed? c int n = 1200, r = 0; while (n) { r = r 10 + n % 10; n /= 10; } printf("%d", r);
- What is printed? c enum { R = 4, W = 2, X = 1 }; int perm = R | X; perm |= W; perm &= ~R; perm ^= X; printf("%d %d", perm, (perm & W) != 0);
- What is printed? c printf("%d", 5["abcdef"] - 'a');