> For the complete documentation index, see [llms.txt](https://liuzhenglaichn.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuzhenglaichn.gitbook.io/algorithm/cpp/overflow.md).

# Overflow

If we are detecting if `a * 10` will overflow `INT_MAX`, we compare `a` with `INT_MAX / 10`. If `a > INT_MAX / 10`, it will overflow.

If we are detecting if `a * 10 + b` will overflow `INT_MAX`, we use this check: If `a > INT_MAX / 10 || (a == INT_MAX / 10 && b > INT_MAX % 10)`, it will overflow.
