Binary Search Implementation in C++ In computer science, binary search, also known as half-interval search or logarithmic search, is a search algorithm that finds the position of a target value within a sorted array.

The code returns true if an element is present in the array else returns false.

Any suggestion in improving the code is welcome.

Binary_Search.h

#ifndef BINARY_SEARCH_H
#define BINARY_SEARCH_H

bool binary_search(int ar[], int low, int high, int key);

#endif // BINARY_SEARCH_H


Binary_Search.cpp

#include &lt;iostream&gt;
#include "Binary_Search.h"

/* search a key in an array using binary search */
bool binary_search(int ar[], int low, int high, int key)
{
  int mid;

  while ( low &lt;= high )
    {
      // find the middle index
      mid = low + ((high - low) &gt;&gt; 1);

      if ( ar[mid] == key ) // key found
        {
          return true;
        }
      else if ( ar[mid] &gt; key ) // key may be on the left half
        {
          high = mid - 1;
        }
      else if ( ar[mid] &lt; key ) // key may be on the right half
        {
          low = mid + 1;
        }
    }

  // key not found
  return false;
}

int main()
{
  int ar[] = {1, 7, 9, 10, 28, 28, 36, 49, 68, 99};

  for ( int i = 0; i &lt; sizeof(ar) / sizeof(ar[0]); ++i )
    {
      if ( binary_search(ar, 0, sizeof(ar) / sizeof(ar[0]) - 1, ar[i]) )
        {
          std::cout &lt;&lt; ar[i] &lt;&lt; " is present" &lt;&lt; std::endl;
        }
      else
        {
          std::cout &lt;&lt; ar[i] &lt;&lt; " is not present" &lt;&lt; std::endl;
        }
    }

  int ar1[] = {-1, 2, 3, 12, 23, 50, 90, 98, 100};
  for ( int i = 0; i &lt; sizeof(ar1) / sizeof(ar1[0]); ++i )
    {
      if ( binary_search(ar, 0, sizeof(ar) / sizeof(ar[0]) - 1, ar1[i]) )
        {
          std::cout &lt;&lt; ar1[i] &lt;&lt; " is present" &lt;&lt; std::endl;
        }
      else
        {
          std::cout &lt;&lt; ar1[i] &lt;&lt; " is not present" &lt;&lt; std::endl;
        }
    }
  return 0;
}
Interface
Passing an array and then two indexes is a very C style of interface. In C++ it is much more common to pass two iterators. An iterator is a generalized form of pointer.
So rather than:
bool binary_search(int ar[], int low, int high, int key);

I would use:
template&lt;typename I&gt;
bool binary_search(I low, I high, int key);

Also rather than pointing at the first and last elements iterator ranges use a first and one past the last. This makes calculating sizes easier.
Code Review
Don't use &gt;&gt; 1 to represent a divide by 2. The point of high level code is to write it so that it is easy for humans to read. That is not obvious. Also the compiler can do these micro optimizations much better than you. So don't try and confuse it. Just write code in the most readable way possible.
Don't use sizeof(ar) / sizeof(ar[0]) it is so easy to break as array collapse into pointers at the drop of a hat. Use std::size() which works for arrays/containers but will fail to compile for pointers (which is what you want).
But if you switch to using Iterator based interface then you should use std::begin() and std::end().
Style
Your bracing style is uncommon. But not so egregious that I would complain about. Normally brace style is defined by a local style guide. So if you are in a compnany or project just check that.
 // Most common C++ styles
 if ()
 {
     Statement;
 }

 // or
 if () {
     Statement;
 }