码迷,mamicode.com
首页 > 其他好文 > 详细

使用头文件climits中的符号常量获知整型数据的表数范围---gyy整理

时间:2016-03-03 19:30:32      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

在头文件climits(limits.h)以宏定义的方式定义了各种符号常量来表示各种整型类型表示数的范围,如int的最大最小值,long的最大最小值等。

 

 

符号常量

表示

CHAR_BIT

char 的位数

CHAR_MAX

char 的最大值

CHAR_MIN

char 的最小值

SCHAR_MAX

signed char 的最大值

SCHAR_MIN

signed char 的最小值

UCHAR_MAX

unsigned char 的最大值

SHRT_MAX

short 的最大值

SHRT_MIN

short 的最小值

USHRT_MAX

unsigned short 的最大值

INT_MAX

int 的最大值

INT_MIN

int 的最小值

UNIT_MAX

unsigned int 的最大值

LONG_MAX

long 的最大值

LONG_MIN

long 的最小值

LONG_MAX

unsigned long 的最大值

 

 

[cpp] view plain copy
 
  1. #include <iostream>     
  2. #include <climits>     
  3. using namespace std;    
  4. int main()    
  5. {    
  6.     cout << "Size:" << endl;    
  7.     cout << "int is     "   << sizeof (int)     << "bytes." << endl;    
  8.     cout << "short is   "   << sizeof (short)   << "bytes." << endl;    
  9.     cout << "long is    "   << sizeof (long)    << "bytes." << endl << endl;     
  10.     cout << "Bits per byte = " << CHAR_BIT << endl << endl;    
  11.    
  12.     cout << "Maximum values:" << endl;    
  13.     cout << "int:           "   << INT_MAX << endl;    
  14.     cout << "short:         "   << SHRT_MAX << endl;    
  15.     cout << "long:          "   << LONG_MAX << endl;    
  16.     cout << "char:          "   << CHAR_MAX << endl;    
  17.     cout << "signed char:   "   << SCHAR_MAX << endl;    
  18.     cout << "unsigned int:  "   << UINT_MAX << endl;    
  19.     cout << "unsigned short:"   << USHRT_MAX << endl;    
  20.     cout << "unsigned long: "   << ULONG_MAX << endl;    
  21.     cout << "unsigned char: "   << UCHAR_MAX << endl << endl;    
  22.     
  23.     cout << "Minimum values:" << endl;    
  24.     cout << "int:           "   << INT_MIN << endl;    
  25.     cout << "short:         "   << SHRT_MIN << endl;    
  26.     cout << "long:          "   << LONG_MIN <<endl;    
  27.     cout << "char:          "   << CHAR_MIN <<endl;    
  28.     cout << "signed char:   "   << SCHAR_MIN  <<endl;    
  29.     
  30.     system("pause");    
  31.     
  32.     return 0;    
  33. }     



 

运行结果

技术分享

 

结果与下标一致。

技术分享

技术分享

 

注意:头文件climits中的符号常量是获知整型数据的表数范围,并不能获取浮点类型数据的表数范围。

<cfloat>  该头文件包含了系统的浮点数的长度限制,它以取代了头文件<float.h>
<climits>该头文件包含了系统的整数长度的限制,它已取代了头文件<limits.h>

使用头文件climits中的符号常量获知整型数据的表数范围---gyy整理

标签:

原文地址:http://www.cnblogs.com/litao0505/p/5239535.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!