This is a simple recursive function of quicksort algorithm and I didn't find return statement in this function so will it not empty the stack after the last recursion?
void quicksort(int arr[], int p, int r){
int q = partition(arr, p, r);
if(p < r){
quicksort(arr,p, q-1);
quicksort(arr,q+1, r);
}
}
This function has no return statemnt so will the recursive functions stay on the stack forever or will they ever get emptied?
The stack frame for the function is cleared when it eventually exits.
An explicit return statement is not necessary for this to happen; when the program flow comes across the closing brace the function will exit anyway, and its stack frame will be cleared.
Another typical way a function can exit without return (albeit not in C) is by throwing an exception; again, the stack frame will be cleared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With