UINT_MAX与C中的ULONG_MAX相同 [英] UINT_MAX the same as ULONG_MAX in C

查看:647
本文介绍了UINT_MAX与C中的ULONG_MAX相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在解决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_MAXULONG_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.其次,标准说最小值值为65535.它可以(通常是更大).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆