Is there any hard-wired limit on recursion depth in C

前端 未结 4 1487
野的像风
野的像风 2021-02-13 09:54

The program under discussion attempts to compute sum-of-first-n-natural-numbers using recursion. I know this can be done using a simple formula n

4条回答
  •  北海茫月
    2021-02-13 10:36

    There is no theoretical limit to recursion depth in C. The only limits are those of your implementation, generally limited stack space.
    (Note that the C standard doesn't actually require a stack-based implementation. I don't know of any real-world implementations that aren't stack based, but keep that in mind.)

    A SIGSEGV can be caused by any number of things, but exceeding your stack limit is a relatively common one. Dereferencing a bad pointer is another.

提交回复
热议问题