AP® Computer Science A glossary
Integer overflow
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
What happens when an int expression would go outside the range Integer.MIN_VALUE to Integer.MAX_VALUE: the result is an int in range, but not the expected value.
Appears in the course and exam description (CED): 1.5.B.11.5.B.21.5.B.3
An int is stored in 4 bytes, so it must lie between Integer.MIN_VALUE and Integer.MAX_VALUE, inclusive. Overflow reports no error; the program keeps running with the wrong value.
int big = Integer.MAX_VALUE;
System.out.println(big + 1);
Output:
-2147483648 Learn it properly, with a checkpoint 1.5 Casting and Range of Variables