If there is a case where the high number is INT_MAX then while calculating the mid there might be overflow of number as INT can maximum hold INT_MAX and cannot hold more than that so major use long long instead of int while calculating the mid or if you wanted the int then write the alternative way as mid = low + (high - low)/2 .