C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C#

What is the base case?

4th Jan 2023, 6:20 PM
Giovanni Paolo Balestriere
Giovanni Paolo Balestriere - avatar
2 Answers
+ 4
Giovanni Paolo , base case is used in recursion. It is the condition, which will stop the call of the function - the recursive call. It is important to think about the base case first, otherwise if you forget it will run forever. For more info follow the link: https://www.geeksforgeeks.org/recursive-functions/
4th Jan 2023, 6:37 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 2
Hello, Yes as TheWh¡teCat 🇧🇬 said, the base case is the stopping condition that is required to stop the subroutine from calling itself and allowing it to 'unwind'. Without the base case, the subroutine will keep calling itself without stopping which will eventually cause a stack overflow error or a memory error (where memory runs out). Hope that helps
4th Jan 2023, 6:57 PM
Hassanah
Hassanah - avatar