unsigned_int_overflow

PHOTO EMBED

Fri Mar 11 2022 10:45:42 GMT+0000 (Coordinated Universal Time)

Saved by @gtsekas #c++

#include <iostream>
#include <limits>

int main() {
  unsigned int i = std::numeric_limits<unsigned int>::max();
  std::cout << ++i;
}
content_copyCOPY

Answer The program is guaranteed to output: 0 Explanation Unsigned integers have well defined behaviour when they overflow. When you go one above the largest representable unsigned int, you end up back at zero. According to §[basic.fundamental]¶4 in the C++ standard: "Unsigned integers, declared unsigned, shall obey the laws of arithmetic modulo 2^n where n is the number of bits in the value representation of that particular size of integer."

https://cppquiz.org/