JOB Interview question! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

JOB Interview question!

Hello, found this question into a interview review: "Can a recursive function be declared inline? Argument as much as you can. " It can be done? Advantages? Disadvantages? Thank you!

2nd Feb 2019, 9:18 PM
Cristian-Alexandru Stefan
Cristian-Alexandru Stefan - avatar
3 Answers
+ 10
Yes, a recursive function can be declared inline. However, the recursive function may not be inlined by some compilers. Otherwise, if the function is tail recursive, then the function can be inlined by the compiler. The compiler will create a call graph of a detected cycle to determine the number of inline functions to create. When a limit cannot be determined from a call graph, some compilers will inline recursive functions with a #pragma specifying a max depth level. When that limit is reached, the function will be called to continue the cycle. There could be a performance benefit by eliminating the overhead of new stacks for each function call. However, it could grow the size of the executable.
3rd Feb 2019, 12:52 AM
David Carroll
David Carroll - avatar
+ 5
Interesting. :) Excited to hear what's the solution. My guess would be no, since the compiler can not know how often the function will be calling itself (how often it has to be 'copypasted' in there), except maybe in case of constexpr where it can be calculated at compile time.
2nd Feb 2019, 9:35 PM
HonFu - avatar
Thank you for sharing great conman question regarding Job, Job interview questions mean HR round interview Questions or their. you should brief describe regarding your questions. i found conman Job interview Questions with Answers if you have any questions you can ask.
7th Feb 2019, 7:22 AM
Manchun - avatar