!= and == on arithmetic types perform the so-called ordinary arithmetic conversions on their operands. Here we apply one operand of type unsigned X and one operand of type signed X , where X is one of int , long and long long , ordinary arithmetic conversions convert the signed operand to unsigned type before performing the comparison.
Therefore, when you compare ua (of type unsigned int ) and -1 (of type signed int ), -1 converted to type unsigned int (conceptually, adding 2 32 assuming a 32-bit int ), and the result is compared with the value of ua .
source share