Stack overflow caused by recursive function

后端 未结 6 1314
面向向阳花
面向向阳花 2020-11-27 20:25

I\'m a beginner in C++. Yesterday I read about recursive functions, so I decided to write my own. Here\'s what I wrote:

int returnZero(int anyNumber) {
    if         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 21:01

    Your stack is limited in size and so when you make 4793 calls you are hitting the limit while 4792 just comes in under. Each function call will use some space on the stack for house keeping and maybe arguments.

    This page gives an example of what a stack looks like during a recursive function call.

提交回复
热议问题