Multiple choice

What happens when you try to assign a value larger than the maximum possible integer to an int variable in C++?

  1. The program terminates

  2. You get an overflow error

  3. The value becomes a negative value

  4. The value becomes zero

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When a signed integer overflows (value exceeds maximum representable), it wraps around due to two's complement representation. The most significant bit (sign bit) flips, making the value negative. For example, if INT_MAX is 2147483647, adding 1 gives -2147483648 (INT_MIN). This is undefined behavior in C/C++ but typically results in wraparound.