Q:

Binary Search dosen't find the right value

I create a vector with 1000 elements, the value of the elements is the index itself
V[100] = 100, V[50] = 50 etc.
When I call the binary search by the value it must return to me the index, what is itself
so binary_search(vector, begin, end, 50) must returns to me 50, but returns 30. I tried to debug with gdb, but can't find anything wrong.
Code:
int rbb(int *v, int left, int right, int val) 
{

    int mid = (left + right) / 2;  //middle element

    if (right < left) //stop codition, pointers shifted
        return -1;

    if (val == v[mid]) //found value
        return mid;  

    if (val > v[mid]) //value is on vector right portion
        rbb(v, mid+1, right, val);

    if (val < v[mid]) //value is on vector left portion
        rbb(v, left, mid-1, val);

}

int main () 
{

    int v[1000];

    for (int i = 0; i < 1000; i++)
        v[i] = i;

    int x = rbb(v, 0, 999, 300);
    printf("%d", x);
}

A:

Problem with your code is that you are not returning the value from the recursive call if rbb function. You should modify your code 
if (val > v[mid]) //value is on vector right portion
    return rbb(v, mid+1, right, val);

if (val < v[mid]) //value is on vector left portion
    return rbb(v, left, mid-1, val);

