Arrays - binary search doubt

#include
#include
using namespace std ;

bool compare( int n , int val , int a[])
{ int s = 0 ;
int e = n - 1 ;
int mid ;
while(s <= e)
{
mid = (s+e)/2 ;

    if( a[mid]== val)
    {    return mid ;
    }
    if( a[mid]> val )
    {
        e = mid - 1 ;
    }

    else if( a[mid]< val )
    {
        s = mid + 1 ;
    }
}

return -1 ;

}

int main()
{
int n ;
cin>> n ;

int a[n] ;

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

int val ;
cin>>val ;

cout<< compare(n , val , a) <<endl ;

return 0 ;
}

why is the output always coming 1 ?

@khushijain hey khushi this is bool function you pass when it’s return mid it give 1. but if you make bool function you should return false and true but for this question you have to make int type function.

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.