In the below binary search function returning value of integer type, why should we use the return value in both the else if statement when there is a recursive call? The code won't work if I directly use recursive call rather than using it in return.
int binarysearch(int l,int h,int key)
{
int mid;
mid=(l+h)/2;
if(l<=h)
{
if(key==a[mid])
return mid;
else if(key>a[mid])
return(binarysearch(mid+1,h,key));
else if(key<a[mid])
return(binarysearch(l,mid-1,key));
}
else
return -1;
}