Integer Overflow and Type Casting
Assume score1, score2, and score3 are integer variables that hold large values. Which of the following expressions correctly calculates the average of these three scores while avoiding potential integer overflow?
A
(score1 + score2 + score3) / 3
B
score1 / 3 + score2 / 3 + score3 / 3
C
(double)(score1 + score2 + score3) / 3
D
((double)score1 + score2 + score3) / 3
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE