Why error in this code?

#include
using namespace std;

int search(int arr,int n,int key){

int start=0;
int end=n-1;

int middle=(start+end)/2;

while(start<end){
	
	
	if(arr[middle]==key) return middle;
	else if(arr[middle]<key){
		start=middle;
	}
	else{
		end=middle;
	}
}

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;

search(arr[n],n,key);

return 0;

}

hi @anshul3558_e8c9aa486c392ca3
start <= end
and middle should be inside while loop

ITS SHOWING THIS ERROR!

source.cpp: In function ‘int search(int, int, int)’:
source.cpp:15:15: error: invalid types ‘int[int]’ for array subscript
15 | if(arr[middle]==key) return middle;
| ^
source.cpp:16:20: error: invalid types ‘int[int]’ for array subscript
16 | else if(arr[middle]<key){
| ^

hi @anshul3558_e8c9aa486c392ca3 send the code on ide.codingblocks.com

hi @anshul3558_e8c9aa486c392ca3 updated

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.