recursion using only heap area

前端 未结 6 1644
你的背包
你的背包 2021-02-10 08:51

Are there examples of recursion using only heap area?

6条回答
  •  别那么骄傲
    2021-02-10 09:25

    In order for a function to be recursive, it must call itself at least once. When it calls itself, it places a pointer to itself on the stack for the recursive call's return. The stack, of course, is not the heap, and therefore a recursive function which uses only the heap is not possible.

    (At least, not in C. Functional languages are optimized to re-use stack space and not allocate pointers for return calls)

提交回复
热议问题