+ 1

What happens if a variable is influenced in an invalid way in C++?

If you add 9 billion to an int, what type of error will happen, can you have this trigger an event, like setting the int to 0?

31st Jan 2019, 5:01 PM
Caleb Hale
Caleb Hale - avatar
2 Respostas
+ 2
If this happens, can you have a .fail() type thing to check if it broke and do something, like set it to 0 or 32767?
31st Jan 2019, 9:58 PM
Caleb Hale
Caleb Hale - avatar
+ 1
It will throw an error like Memory Type Exceeded or somthing like this. An int can store only 16bits, and can have values from 32767 to -32768 (don't know if the limit is larger now), so it just can't handle a so big value. It's for type float. There can be till 3.4+e38.
31st Jan 2019, 6:23 PM
Charlie S
Charlie S - avatar