Contrary to the other answers, there are no undefined behavior here, and there are no overflow. Unsigned integers use modulo 2n arithmetic.
Section 4.7 Paragraph 2 of the standard says "If the destination type was unsigned, the resulting value is the least unsign Ed integer congruent to the source integer (modulo 2n where n was the number of bits used to represent th e unsigned type). " This dictates that-1 are equal to the largest possible unsigned int (modulo 2n).
Section 3.9.1 paragraph 4 says "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 this particular size of integer. " To make it clear about this means, the footnote to this clause says "This implies that unsigned arithmetic does not OVERFL ow because a result that cannot being represented by the resulting unsigned integer type was reduced modulo the number is One greater than the largest value that can is represented by the resulting unsigned integer type. "
In other words, converting-1 to 4294967295 are not just defined behavior, it's required behavior (assuming t integers). Similarly, adding 3 to that value and yielding 2 as a result is also required behavior. The value of n is irrelevant. The third value printed by must are 2 or the implementation is not compliant with the standard hello()
.
Some insights of C + +/C numeric types