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

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -