title: C++ code works for some input, but doesn't on others
body: <p>I'm writing a code which will sort a user input array in ascending order (using quicksort) and uses a recursive function to find if a specific element in the array exists or not. My quicksort function works, but I'm struggling with getting the right answer for  recursivesearch function. </p>
  
  <p>This is my main   </p>
  
  <pre><code> #include &lt;iostream&gt;
      #include &lt;string&gt;
  
  using namespace std;
  int recursivesearch(int arr[], int start, int end,int no);
  
  int main () {
      int no,size;                            // 'no' is what element to search, should be 1 in this case
  cout &lt;&lt; "Enter what to search" &lt;&lt; endl;          // element we need to search
  cin &gt;&gt; no;
  cout &lt;&lt; endl;
  cout &lt;&lt; "Enter size of array" &lt;&lt; endl;      // array size im testing is 8         
  cin &gt;&gt; size;
  
  int array[size];
  for (int i=0;i&lt;size;i++) {
      cin &gt;&gt; array[i];
  }
  if (recursivesearch(array,0,size-1,no)==0) {
      cout &lt;&lt; "false" &lt;&lt; " ";
  } 
  else {
      cout &lt;&lt; "true" &lt;&lt; " ";
  }
  cout &lt;&lt; endl;
  
  }
  </code></pre>
  
  <p>This is the recursive function</p>
  
  <pre><code>int recursivesearch(int arr[], int start, int end, int number) {
      int middle=0;            
      int element=number;
      int length=(end-start)+1;
  
      if (length%2!=0) {              // defining the size depending on if its even or odd
          middle=(start+end)/2;
      }
      else {
         middle=(start+end)/2+1;
      }
  
      if (arr[middle]==element){     // base case, if we find it, return the index
          return middle;
      }
      else if (length==1 &amp;&amp; arr[middle]!=element) { // if we can't find it return 0
          return 0;
      }
  
      else if (arr[middle]&gt;element) {
           recursivesearch(arr,start,middle-1,element); // if the middle index has value greater than element, call recursion for the left-hand side of the array from the middle point
      }
      else if (arr[middle]&lt;element) { // if the middle index has value less than element, call recursion for the RHS from the middle point
          recursivesearch(arr,middle+1,end,element);
      }
  }   
  </code></pre>
  
  <p>I am only testing if number '1' is in the array as that's what I've been specified to do.
  This only works for specific cases. If i write [-5 1 3 4 5 100 2014 7777] it works (shows true). But if I write [-5 0 1 3 4 5 100 2014 7777] I get segmentation fault. I don't understand how changing 1 number can lead to a segmentation fault. Can someone help me out?    </p>