UINT_MAX与C中的ULONG_MAX相同 [英] UINT_MAX the same as ULONG_MAX in C
问题描述
在解决K& R C书中的练习时,我偶然发现了练习2.1.
While solving exercises from the K&R C book, I stumbled upon the exercise 2.1.
起初我得到的UINT_MAX
和-1
一样,但是后来我使用了%u
占位符,但是现在它给了我与ULONG_MAX
相同的数字.
At first I got as UINT_MAX
as -1
, but then I used the %u
placeholder, but now its giving me the same number as ULONG_MAX
.
在附录B的书中,他们说UINT_MAX
应该是65535
,而ULONG_MAX
应该是4294967295
,但是在进行练习时,它同时给出了UINT_MAX
和ULONG_MAX
的含义4294967295
.
In the book in Appendix B, they say that UINT_MAX
should be 65535
and ULONG_MAX
should be 4294967295
, but when running the exercise, its giving me for both UINT_MAX
and ULONG_MAX
as 4294967295
.
那是为什么?
推荐答案
首先,打印unsigned long
的正确方法不是%u
而是%lu
.其次,标准说
First of all, the right way to print an unsigned long
is not %u
but %lu
. Second, the standard says the minimum value of UINT_MAX
is 65535. It can be (and usually is) larger.
5.2.4.2.1整数类型的大小
5.2.4.2.1 Sizes of integer types
其实现定义的值应等于或大于 幅度(绝对值)与所示符号相同.
Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.
这篇关于UINT_MAX与C中的ULONG_MAX相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!