Problem in binary search code

#include
using namespace std;

int binary(int arr[], int key, int start, int last)
{

int mid= (last-start)/2;
if(key==arr[mid]) return mid;
else if(key<arr[mid])
    return binary(arr, key, start, mid-1);
else if(key>arr[mid])
    return binary(arr, key, mid+1, last);

return -1;

}
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{

    cin>>arr[i];
}
int key;
cin>>key;
cout<< binary(arr,key,0,n-1);

}
//This is the code. Pls Help

Hey @anshufirefox try to share your code using ide.codingblocks.com , if you don’t know how to share it using ide.codingblocks.com you can also ask me that.

Also your previous doubt aren’t answered, you can reopen that too :slight_smile:

How to share code using ide.codingblocks?

Open ide.codingblocks.com
Paste your code there which you want me to debug
Then click file , here you will see a safe button
Press it. Wait for 2 seconds it will get save and after that it will generate a special url like ide.codingblocks.com/s/28xxxx share that url with me.
Still an issue , you can ask me that too :slight_smile:

The url isn’t being generated


Click on this url, you have to send thIs url


Does this work?

Yes, now be patient. I’ll debug it and let you know

This is your debugged code, instead of - , you have to do +

Thank you so much. Really helpful.

Don’t forget to give your ratings :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.