Integer Overflow

Definition : Overflow the limitation of a program with an integer.

Limitations On Integers in C

In any language, not only C, have its own and . It has it's own limitation value. However, in can be limited by the program itself.

Min
Variable Type / Type Modifiers
Max

-32,768 bits

short

32,767 bits

-2,147,483,648

int

2,147,483,647

-9,223,372,036,854,775,808 bits

long

9,223,372,036,854,775,807 bits

0

unsigned short int

65,535

0

unsigned int

4,294,967,295

-128

signed char

127

0

unsigned char

255

Drawing
This image hopefully helps you to understand the explaination below

For a better understanding on how it works, look at your analog clock. The clock has a limit of 12 numbers only. Let say the time right now is 9 am. In 12 hours, the clocks points back at number 9 but in pm. It does not point at number 21 right? Yeah that's how i understanding the limitations (i know it does not make sense, but why not 🤣)

Tips 📋

  1. Knowing the limitation of the variable type is a must

  2. Try to input something so that the variable will exceed the limit

  3. --

Last updated