Casting and Ranges of Variables

AP Computer Science A· difficulty 4/5

int max = Integer.MAX_VALUE;
System.out.println(max + 1);

What is printed?

  • A

    0

  • B

    -2147483648

    check_circle
  • C

    Integer.MAX_VALUE

  • D

    2147483648

Explanation

Adding 1 to Integer.MAX_VALUE overflows and wraps around to Integer.MIN_VALUE, which is -2147483648.

Want 10 more like this — adaptive to your weak spots?

Related questions