- this function is for sorted arrays but when i am inputting unsorted array then also its giving the correct ans ?
- in the function binary_search(arr) , what is this arr ( the name of array or what) ?
Doubt regarding few things here?
prototype of binary_search is:
binary_search(startaddress, endaddress, valuetofind)
startaddress: the address of the first element of the array.
endaddress: the address of the last element of the array.
valuetofind: the target value which we have to search for.
the array provided has to be sorted
it’s completely on luck if mid element matches the value to find
eg 
int arr[]={9,5,8,7,6,0,3};
int n=sizeof(arr)/sizeof(int);
cout<<binary_search(arr,arr+n,3)<<endl;
output=0;
u can learn more here: -
cplusplus.com/reference/algorithm/binary_search/
In case of any doubt feel free to ask 
mark your doubt as resolved if you got the answer
1 Like