February 2014
Beginner
1248 pages
62h 25m
English
In Fig. 4.8, line 21
total = total + grade; // add grade to total
added each grade entered by the user to the total. Even this simple statement has a potential problem—adding the integers could result in a value that’s too large to store in an int variable. This is known as arithmetic overflow and causes undefined behavior, which can lead to unintended results (http://en.wikipedia.org/wiki/Integer_overflow#Security_ramifications). Figure 2.7’s Addition program had the same issue in line 23, which calculated the sum of two int values entered by the user:
sum = number1 + number2; // add numbers, then store total in sum
The maximum and minimum values ...
Read now
Unlock full access