← Quiz: Searching and Sorting in C: all 10 questions
Quiz: Searching and Sorting in C · Question 6 of 10
Why write mid = low + (high - low) / 2 instead of (low + high) / 2?
Why write mid = low + (high - low) / 2 instead of (low + high) / 2?
- A.It is faster
- B.It rounds up instead of down
- C.low + high can overflow an int for very large indexes; this form cannot
- D.It is needed for unsorted arrays
Answer & explanation
Correct answer: low + high can overflow an int for very large indexes; this form cannot
Both give the same middle, but only this form is safe when low and high are close to INT_MAX.
Can you get the rest right without peeking?
Take the timed Quiz: Searching and Sorting in C quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →