ProgrammingHardProduct company OA
What does p(5) print?
What does p(5) print?
void p(int n) {
if (n <= 0) return;
p(n - 2);
printf("%d", n);
p(n - 3);
}- A. 13252
- B. 1325
- C. 5312
- D. 1352
Correct answer: D. 1352
This is an in-order walk: left subtree p(n − 2), then n, then right subtree p(n − 3). p(5) → p(3) → p(1) prints 1, then 3 (p(0) is empty), then 5, then p(2) prints 2. Result 1352.
More C Programming questions
- Which statement about this C declaration is true? c char a[5] = "hello";
- What is printed? c #define CUBE(x) ((x) (x) (x)) int n = 0; int f(void) { n++; return 2; } int main(void) { int r = CUBE(f()); printf("%d…
- What is printed? c unsigned char rotl(unsigned char v, int k) { return (unsigned char)(v << k | v >> (8 - k)); } int main(void) {…
- With int a[3], p = a; which statement fails to compile?
- Assume 4-byte int. What is printed? c struct Msg { int len; char data[]; }; struct Msg m = malloc(sizeof m + 10); printf("%zu", sizeof m);
- What is printed? c printf("%zu %zu", sizeof("ab" "cd"), strlen("ab0cd"));