C/C中的(limits.h)++

积分值的最大值和最小值非常有用,或者简单地说,任何积分类型的极限在编程中都起着相当大的作用。可以使用不同的宏来代替记忆这些值。

null

(limits.h) 定义整数类型的大小。 此标头定义了常数,其中包含特定系统和所用编译器实现的基本整数类型的限制。 基本浮点类型的限制在 )中定义。 宽度特定整数类型和其他类型定义类型的限制在 )中定义。

不同的宏常量包括:

1. 查鲁敏:

Minimum value for an object of type charValue of CHAR_MIN is either -127 (-27+1) or less* or 0

2. CHAR_MAX:

Maximum value for an object of type charValue of CHAR_MAX is either 127 (27-1) or 255 (28-1) or greater*    

3. 施图敏:

Minimum value for an object of type short intValue of SHRT_MIN is -32767 (-215+1) or less*

4. SHRT_MAX:

Maximum value for an object of type short intValue of SHRT_MAX is 32767 (215-1) or greater*

5. USHRT_MAX:

Maximum value for an object of type unsigned short int    Value of USHRT_MAX is 65535 (216-1) or greater*

6. INT_MIN:

Minimum value for an object of type int    Value of INT_MIN is -32767 (-215+1) or less*

7. INT_MAX:

Maximum value for an object of type int    Value of INT_MAX is 32767 (215-1) or greater*

8. UINT_MAX:

Maximum value for an object of type unsigned int    Value of UINT_MAX is 65535 (216-1) or greater*

9 龙宇敏:

Minimum value for an object of type long int    Value of LONG_MIN is -2147483647 (-231+1) or less*

10 LONG_MAX:

Maximum value for an object of type long int    Value of LONG_MAX is 2147483647 (231-1) or greater*

11 ULONG_MAX:

Maximum value for an object of type unsigned long int    Value of ULONG_MAX is 4294967295 (232-1) or greater*

12 隆敏:

Minimum value for an object of type long long int    Value of LLONG_MIN is -9223372036854775807 (-263+1) or less*

13 朗格·马克斯:

Maximum value for an object of type long long int    Value of LLONG_MAX is 9223372036854775807 (263-1) or greater*

14 尤龙·马克斯:

Maximum value for an object of type unsigned long long int    Value of ULLONG_MAX is 18446744073709551615 (264-1) or greater*

注**实际值取决于特定的系统和库实现,但应反映目标平台中这些类型的限制。 您的机器的值可能取决于它是32位机器还是64位机器。

兼容性: Langymin,LangyMax和ULLang-Max定义为符合C 1999或更高标准(仅包含C++标准2011:C++ 11)的库。 这些宏的两个应用程序是检查整数溢出和计算非常大或非常小元素数组中的最小值或最大值。

下面的程序将显示您机器的相应值:

C++

// C++ program to demonstrate working of
// constants in climits.
#include <climits>
#include <iostream>
using namespace std;
int main()
{
cout << "CHAR_MIN : " << CHAR_MIN << endl;
cout << "CHAR_MAX : " << CHAR_MAX << endl;
cout << "SHRT_MIN : " << SHRT_MIN << endl;
cout << "SHRT_MAX : " << SHRT_MAX << endl;
cout << "USHRT_MAX : " << USHRT_MAX << endl;
cout << "INT_MIN : " << INT_MIN << endl;
cout << "INT_MAX : " << INT_MAX << endl;
cout << "UINT_MAX : " << UINT_MAX << endl;
cout << "LONG_MIN : " << LONG_MIN << endl;
cout << "LONG_MAX : " << LONG_MAX << endl;
cout << "ULONG_MAX : " << ULONG_MAX << endl;
cout << "LLONG_MIN : " << LLONG_MIN << endl;
cout << "LLONG_MAX : " << LLONG_MAX << endl;
cout << "ULLONG_MAX : " << ULLONG_MAX << endl;
return 0;
}


输出(取决于机器):

CHAR_MIN : -128CHAR_MAX : 127SHRT_MIN : -32768SHRT_MAX : 32767USHRT_MAX : 65535INT_MIN : -2147483648INT_MAX : 2147483647UINT_MAX : 4294967295LONG_MIN : -9223372036854775808LONG_MAX : 9223372036854775807ULONG_MAX : 18446744073709551615LLONG_MIN : -9223372036854775808LLONG_MAX : 9223372036854775807ULLONG_MAX : 18446744073709551615

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享