title: Binary search in an array works after rewriting it in the exact same way
body: <p>I'm performing a binary search in an array, looking for a specific value inside of it. When I wrote the code the first time, my for loop for sorting the array in ascending order always added a 0 right in the middle of it so that I could not search for the last element of the array, since the middle part got now replaced with 0 and I don't know why, then I rewrote the program in the exact same way and suddenly it worked.</p>
  <p>I noticed in the new rewritten program that when I write a for loop for iterating through the array and printing out its contents before the for loop for sorting the array that it adds a 0 in the middle again, if I delete that for loop everything works fine. I don't understand why that is, could somebody explain that to me please?</p>
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      int Arr[] = {1,-1,2,-2, 3,-3,4,-4,5,-5,6,-6,7,-7};
      int Temp, Size, Low = 0, High, Mid, Key, Found = 0;
      Size = (sizeof(Arr) / sizeof(Arr[0]));
      High = Size - 1;
  
      cout&lt;&lt;&quot;Enter value of key you want to testsearch for:\n&quot;;
      cin&gt;&gt;Key;
  /*
      for (int i = 0; i &lt; Size; i++)     //if I don't comment out this loop the 0 will get added in
      {                                  //the middle of the array again and I don't know why
          cout&lt;&lt;Arr[i]&lt;&lt;&quot; &quot;;
      }
  */
      for (int Rep = 1; Rep &lt;= Size-1; Rep++)
      {
  
          for (int i = 0, Temp = 0; i &lt; Size; i++)
          {
              if (Arr[i] &gt; Arr[i+1])
              {
                  Temp = Arr[i];
                  Arr[i] = Arr[i+1];
                  Arr[i+1] = Temp;
              }
          }
      }
  
      for (int i = 0; i &lt; Size; i++)
      {
          cout&lt;&lt;Arr[i]&lt;&lt;&quot; &quot;;
      }
  
      for (int i = 0; i &lt; Size; i++)
      {
          Mid = (Low+High)/2;
          if (Arr[Mid] == Key)
          {
              Found = 1;
              break;
          }
          else if (Arr[Mid] &lt; Key)
          {
              Low = Mid+1;
          }
          else if (Arr[Mid] &gt; Key)
          {
              High = Mid-1;
          }
      }
  
      if (Found)
      {
          cout&lt;&lt;&quot;\nGiven key value &quot;&lt;&lt;Key&lt;&lt;&quot; was found.&quot;;
      }
      else
      {
          cout&lt;&lt;&quot;\nGiven key value &quot;&lt;&lt;Key&lt;&lt;&quot; was not found.&quot;;
      }
  
      return 0;
  }
  
  </code></pre>