In the binary search program on page 112, why did we write mid = beg + (end - beg) / 2; instead of mid = (beg + end) /2;
belongs to book: C++ Primer|Stanley B.Lippman, Josee Lajoie, Barbara E.Moo|5th Edition| Chapter number:3| Question number:3.26
All Answers
total answers (1)
 
                         
        
 
     C++ programming
C++ programming
First, there is no operator `
+` for two iterators.Second, for arithmetic types, using `
need an explanation for this answer? contact us directly to get an explanation for this answermid = (beg + end) / 2` may lead to overflow.