之间的真正区别" INT"和" unsigned int类型"
INT
32位int数据类型可以在范围内举行的整数值
2,147,483,648到2,147,483,647。您也可以参考此数据类型
作为签署int或签名。
The 32-bit int data type can hold integer values in the range of −2,147,483,648 to 2,147,483,647. You may also refer to this data type as signed int or signed.
unsigned int类型
32位无符号整型数据
类型可以在0范围内持有整数值4,294,967,295。您
也可参考此数据类型简单地作为无符号。
The 32-bit unsigned int data type can hold integer values in the range of 0 to 4,294,967,295. You may also refer to this data type simply as unsigned.
好吧,但是,在实践中:
Ok, but, in practice:
int x = 0xFFFFFFFF;
unsigned int y = 0xFFFFFFFF;
printf("%d, %d, %u, %u", x, y, x, y);
// -1, -1, 4294967295, 4294967295
没有区别,O.o.我有点糊涂了。
no difference, O.o. I'm a bit confused.
呵呵。在这里你有一个隐式转换,因为你告诉的printf
期望是什么类型的。
Hehe. You have an implicit cast here, because you're telling printf
what type to expect.
试试这个关于大小,而不是:
Try this on for size instead:
unsigned int x = 0xFFFFFFFF;
int y = 0xFFFFFFFF;
if (x < 0)
printf("one\n");
else
printf("two\n");
if (y < 0)
printf("three\n");
else
printf("four\n");