Skip to main content
Logo image

Section 18.11 Overflow

Overflow occurs when a value that you attempt to store in memory is larger than the datatype being used allows.

Activity 18.6.

Remember the binary 2’s complement representation of integers?
Using the sizeof() function, please find out how many bits in memory are used to store an integer on our system (recall that the sizeof() function returns the number of bytes), then use that information to compute the largest integer that can be represented on our system (assuming binary 2’s complement is used). Next, please print out this integer as well as the number you obtain when you add 1 to this integer.

admin.....open in new window

If you are done, please modify your code to perform similarly for the data types short and long.
When you are done, please paste your code into the code submission box below: