Find a missing element in a sorted list I've made a program to find the missing element (if there's one) in a sequential list:

Program criteria:
Returns -1 if a list is sequential, otherwise the missing element in a non-sequential list is returned.
To perform binary search, we need a key to half the problem size. Here the key is to find the distance between the index (low, high) and their corresponding values.
Compilation procedure:
gcc -Wall -g testList.c -o testList

./testList



#include&lt;stdio.h&gt;
int bSearch(int array[], int low, int high){

  int mid = (low + high) / 2;

  if(high == low + 1){
    if(array[high] &gt; array[low] +1){
      return array[low] +1;
    }else{
      return -1;
    }
  }

  if(array[mid] - array[low] == mid - low){
    return bSearch(array, mid, high);
  }else if(array[mid] -  array[low] &gt; mid - low){
    return bSearch(array, low, mid);
  }else{
    return -1;
  }
}


int main(void){

  int array [] = {22, 23, 24, 25, 26, 27, 28, 30};
  int upperBound = (sizeof(array)/sizeof(array[0]))-1;
  printf(&quot;%d\n&quot;, bSearch(array, 0,  upperBound));
  return 0;
}

My questions:

Why does removing the else{} case cause the compiler to give a warning for it?

Can the base case look more elegant?

For code elegance and optimization, can this code be improved?
Why does removing the else{} case cause the compiler to give a warning for it?


The compiler will indeed issue a warning if a value-returning function doesn't return a value for every path.  Ignoring this warning could then cause undefined behavior.

If you intend for bSearch() to return -1 on failure, then you can put just one return -1; at the very end of the function and remove the elses that return -1.