ProgrammingVery hardProduct company OA
What is printed?
What is printed?
int m(int n) { return n > 100 ? n - 10 : m(m(n + 11)); }
int main(void) { printf("%d %d", m(50), m(105)); }- A. 50 95
- B. 61 95
- C. 91 95
- D. 91 105
Correct answer: C. 91 95
This is McCarthy's 91 function: for any n ≤ 100 the nested calls climb above 100 and settle back to exactly 91; for n > 100 it simply returns n − 10. So m(50) = 91 and m(105) = 95.
More C Programming questions
- What is printed? c int h(unsigned a, unsigned b) { int c = 0; for (unsigned x = a ^ b; x; x >>= 1) c += x & 1; return c; } int main(void)…
- What is printed? c int a[] = {10, 20, 30, 40, 50}; int p = &a[3]; printf("%d %d %d", p[-2], -1[p], (p - 1)[-1]);
- What is printed? c struct C { int r, g, b; } c = {.b = 9, .r = 4}; printf("%d %d %d", c.r, c.g, c.b);
- Assume 4-byte int with 4-byte alignment. What is printed? c union U { char c[5]; int i; }; printf("%zu", sizeof(union U));
- Compiled as C99 or later, what is printed? c int i = 1; for (int i = 5; i < 7; i++) { int i = 10; printf("%d ", i); } printf("%d", i);
- What is printed? c printf("%zu", sizeof("1234"));