Why does size of an integer matter? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why does size of an integer matter?

6th Dec 2016, 2:12 PM
Bomte Gapak
Bomte Gapak - avatar
3 Answers
+ 4
Because integer values that are too large or too small may fall outside the allowable bounds for their data type, leading to unpredictable problems that can both reduce the robustness of your code and lead to potential security problems. Following are the errors you may find while defining the integer : 1. Integer Overflow 2. Sign Errors 3. Truncation Integer variables are often used to indicate the number of items that must be stored in an array or other fixed-size buffer. If a variable with an overflow is used for this purpose, the resulting buffer might be too small for the data that will be copied into it. This can cause your program to crash, lead to incorrect behavior, or open security vulnerabilities.
6th Dec 2016, 2:19 PM
Vipul Walia
Vipul Walia - avatar
+ 2
Simply speaking...it matters because there is a predefined size of an integer and if you try to assign a value more than the size of integer...the compiler will crash your program and affect the performance of your system.
2nd Feb 2017, 5:44 AM
Ashu Bagul
Ashu Bagul - avatar
- 1
Because its possible that you will reach the maximum value of Integer if you iterate another time you will be near to the minimum of Integer. Herefore imagine a clock where 12 oClock is 0 and 6 o'clock and a minute is the max value and 6 o'clock is the min value. Ok know speaking in comparison if you go to the max value and go a minute further you will go to 6 o'clock to our min value. Did that example help you?
6th Dec 2016, 2:22 PM
Andreas K
Andreas K - avatar