Why does a recursed return call break out of stack without an explicit return statement?

后端 未结 4 1772
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-11 15:10

I was shown a sample program to demonstrate recursion which looks like it should not work but does. The logic is pretty clear but why does it work even when the recursed fu

4条回答
  •  感动是毒
    2020-12-11 15:35

    Aren't you forgetting a return statement? For normal recursion you need to put a return before isprime(num,i-1); as well.

    I guess this even should give a compile warning if you compile this using strict rules, because the function must always return an int, now it does not (at least if your compiler does not fix this).

提交回复
热议问题