What is overflow and underflow of variables? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is overflow and underflow of variables?

26th Jun 2018, 11:04 PM
Maleeha Khalid
Maleeha Khalid  - avatar
6 Answers
+ 2
Overflow is when you assign a value which is over the maximum permissable value underflow is the opposite and you assign a value which is under the minimum permissable value
26th Jun 2018, 11:29 PM
Agent
Agent - avatar
+ 2
Maleeha same thing really: int a = -9999999999999999; //doesn't work as an integer can hold from -2^32, this is underflow
27th Jun 2018, 9:26 AM
hinanawi
hinanawi - avatar
+ 1
Agent can you give a practical example? in computer?
27th Jun 2018, 8:26 AM
Maleeha Khalid
Maleeha Khalid  - avatar
+ 1
practical example: int a = 999999999999999; //this doesn't work, as an integer can hold values up to 2^31-1 (iirc) so you have an overflow
27th Jun 2018, 9:19 AM
hinanawi
hinanawi - avatar
+ 1
got it ..and example of underflow? hinanawi
27th Jun 2018, 9:25 AM
Maleeha Khalid
Maleeha Khalid  - avatar
+ 1
thank you :)
27th Jun 2018, 9:28 AM
Maleeha Khalid
Maleeha Khalid  - avatar