Returning a pointer in Binary Search

I'm almost sure that this does not result in undefined behaviour as what I'm returning is within range of the supplied pointers.

Still..there may be something I'm not aware of.

<I'm aware of <algorithm> but this is for a homework :( >

Code:

`int* bin_s(int n,int* x, int* y)`

{

if(x==y)

if(*x==n)

return x;

else return 0;

else if (y-x==1||x-y==1)

{

if(n==*x)return x;

else if(n==*y)return y;

else return 0;

}

else

{

int* temp = x+((y-x)/2);

int* result;

if(n>= *temp)

result = bin_s(n,temp,y);

else

result = bin_s(n,x,temp);

return result;

}

}

Does it seem okay?