How does return
work exactly?
I found the below code and am confused how it works.
You can see in the if (n==1)
statement the return
has no value next to it.
void bubbleSort(int arr[], int n) {
// Base case
if (n == 1)
return;
for (int i=0; i<n-1; i++)
if (arr[i] > arr[i+1])
swap(arr[i], arr[i+1]);
return bubbleSort(arr,n-1);
}
How does the return
keyword work in instances such as this?
Basicly this function is recursive and if its void
it can't return value so it's just flag to stop function