When run the code below:
EStackOverFlow will appear.Code:void F() { F(); }
The book says that there is a loop going on. Can anyone explain to me?
Because I think in the Void F function, it will only use itself once.
When run the code below:
EStackOverFlow will appear.Code:void F() { F(); }
The book says that there is a loop going on. Can anyone explain to me?
Because I think in the Void F function, it will only use itself once.
You're looking at infinite recursion. Yes, F only calls itself once, but the call to F calls itself once, which calls itself once, which... the sum of all energy-matter in the universe is insufficient for me to express this in full.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Oh. I get it.
What about the following code?Code:void F(int a) { F(a+1); }
What's the terminating condition (or base case)?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Umm.. What is the meaning of 'terminating condition' ?
Didn't your book give you examples of recursion?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Sorry. my book is in Chinese.
Okay, basically: when does the recursion end? Trace through the code and find out.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
When the condition is not satisfied.
So, what is the condition?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
In the code I have given ? Or?
Yes, the code in post #4.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
um.. after f(a+1)?
Is that an answer to my question or is that a question?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)