Here is MSDN link
From http://msdn.microsoft.com/en-us/library/s3f49ktz(v=VS.80).aspx
It says:
unsigned int : 4byte
Range of Value 0 to 4,294,967,295
Hence my test code:
void main(void)
{
unsigned int sum; //4byte, 32bit
sum = 2147483648; //2^31 represent by 1 followed by 31 0s
printf("sum is %d\n",sum);
sum = sum -1 ; //2^31-1 represent by 0 followed by 31 1s
printf("sum is %d\n",sum);
getchar();
}
I am sure 4,294,967,295=2^32-1, printf will print “0”, dump most significant bit
I think MSDN should wrote range of value: 0 to 2147483647
Is that right?
That’s incorrect, if you want to get 4b you should do
Alternatively
This should give you the correct max value for an unsigned int (as hackish as that is). Also as others pointed out you should use %u as the formatter in your printf so that the value gets interpreted correctly.
An unsigned int uses all bits as magnitude bits so the leading bit is no longer considered a sign bit so that becomes 2^32 – 1 instead of just 2^31 – 1