When you initialize unsigned int a to -1;
it means that you are storing the 2's
complement of -1
into the memory of a
.
Which is nothing but 0xffffffff
or 4294967295
.
Hence when you print it using %x or %u
format specifier you get that output.
By specifying signedness of a variable to decide on the minimum and maximum limit of value that can be stored.
Like with unsigned int
: the range is from 0 to 4,294,967,295
and int
: the range is from -2,147,483,648 to 2,147,483,647
For more info on signedness refer this