Home

Some notes about using unsigned int

The following for loop will never stop

#include <iostream>
for (unsigned i = 5; i >= 0; --i) {
    std::cout << i << std::endl;
}

The reason is that when i is 0, the result of i-1 is 4294967295 (2^32-1) since i is unsigned int.