This is because the return type of count is an unsignedint. When you substract 1 from 0, you do not get -1. Instead you underflow to the highest possible unsigned int. The reason it works in the second version is because you cast it (implicitly) to an int in which the value -1 is legal.