Understanding Overflow and Underflow

Another source of potential conflict can arise when the value of a variable becomes too large or too small for its type for the computer running the application. When this occurs, it's called overflow and underflow. Depending on the computer, this will either cause an error or return alternative results.

This happens most frequently with floats, and it will obviously mess up any calculations made with such a value. When you attempt to print this variable, you'll most likely see either inf or infinity, indicating that the value is out of range.

The best way to avoid these problems is by knowing the limits for a particular type. This information is stored in the limits.h (for integers and characters) and float.h ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.