c++ - Why does this recursive function crash? -
c++ - Why does this recursive function crash? -
int g(int n) { int x = g(n - 1); if (x > 0) { homecoming x + 1; } else { homecoming 1; } }
my guess has first line of function... i'm not sure why case.
if function said this:
int g(int n) { homecoming g(n - 1); }
then not expect work, instead maintain recursing until run out of stack space , programme crashes. putting recursion before exit status in function, doing this.
you should rewrite function performs exit test before calling g()
again.
c++ crash segmentation-fault
Comments
Post a Comment