When you use an unsigned type, all bits are used to represent non-negative values ββ(i.e.> = 0). Think about it as values ββwrap around, so when you decrease below the lower limit (0), you wrap it to the largest value (with 32 bits, 2 ^ 32 - 1).
Also, note that you did not assign a negative value to the variable x , you simply provided an expression that subtracted 1. from it. That is.
x-1
vs
x = x - 1;
although you would receive a warning about this, it will probably depend on the compiler and the warning levels set.
Levon source share