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.
This is a discussion on EStackOverFlow within the C++ Programming forums, part of the General Programming Boards category; When run the code below: Code: void F() { F(); } EStackOverFlow will appear. The book says that there is ...
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.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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)?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Umm.. What is the meaning of 'terminating condition' ?
![]()
Didn't your book give you examples of recursion?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Sorry. my book is in Chinese.
Okay, basically: when does the recursion end? Trace through the code and find out.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
When the condition is not satisfied.
So, what is the condition?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
In the code I have given ? Or?
Yes, the code in post #4.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
um.. after f(a+1)?
Is that an answer to my question or is that a question?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way