ProgrammingHardGATE CS · Campus placements

Is the C standard guaranteed to remove stack frames of tail-recursive calls, so that deep tail recursion cannot overflow the stack?

  1. A. No, the standard does not require tail-call elimination, so deep recursion may overflow the stack
  2. B. Yes, every conforming compiler must optimise tail calls
  3. C. Yes, but only when compiled with optimisation enabled
  4. D. No, C forbids recursion inside functions with a return value

Correct answer: A. No, the standard does not require tail-call elimination, so deep recursion may overflow the stack

Tail-call elimination is an optimisation, and the C standard leaves call-stack use to the implementation. Competitive solutions should write deep recursions as loops with an explicit stack.

More C Programming questions

Exams that ask this topic