Similar questions 1 more →
Recursion
![Question 13(a), GATE 2001: abc(s) returns at the null terminator; otherwise it calls abc(s+1) twice and then prints s[0]. main calls abc("123").](../../assets/questions/CS-2001-Q76-1.webp)
![Question 13(a), GATE 2001: abc(s) returns at the null terminator; otherwise it calls abc(s+1) twice and then prints s[0]. main calls abc("123").](../../assets/questions/CS-2001-Q76-2.webp)
Answer & solution
Answer: 3323321 (no official key was published)
Step through it (33 steps)
Let F(s) be the string printed by a call. F(empty)=empty and F(cs)=F(s)F(s)c. Therefore F("3")="3", F("23")="3"+"3"+"2"="332", and F("123")="332"+"332"+"1"="3323321". The recursive calls finish before the current character is printed, so the initial character appears last. No spaces or newline are printed.