Hi ,
I studied recursion on c programming and I have one concern about stack memory handling on recursive calls while recursive function is getting executed. specifically how things are done on stack memory ..
assume given this recursive function as following :
Code:
void recursion(int num) {
if (num == 1 || num < 1 )
{
return ;
}
recursion(num/10);
}
assume num given as input 100 to the function, as well as we have stack
memory given from 0 - 100 bytes , meaning that there is given implicitly integer array where its size from index 0 to 100, lets say given where recursion function work upon it.
Now my concern is how I can by recursive calls keep tracking that I didnt arrive the maximum of stack memory? for not reaching stack over flow ... meaning how can I be sure that on the next recursive call that there is enough stack memory for next recursive call and if there is no sufficient space left on stack memory
then recursion shall stop.
How I can keep tracking that? I was thinking about pointers to save/store some pointers aside and ampersend "&" related somehow to tackle that issue.
any idea or any help to tackle this issue? by the way the original function (given above recursion function) can be edited and to add any other additional functions ..
Thanks.