C标准库——limitis.h

这个标准库定义了各种常量表示整型数据类型的能够表示数据的范围。

 

nameexpressesmin. magnitude*
CHAR_BIT Number of bits for a charobject (byte) 8
SCHAR_MIN Minimum value for an object of type signed char -127
SCHAR_MAX Maximum value for an object of type signed char 127
UCHAR_MAX Maximum value for an object of type unsigned char 255
CHAR_MIN Minimum value for an object of type char either SCHAR_MIN or 0
CHAR_MAX Maximum value for an object of type char either SCHAR_MAX or UCHAR_MAX
MB_LEN_MAX Maximum number of bytes in a multibyte character, for any locale 1
SHRT_MIN Minimum value for an object of type short int -32767
SHRT_MAX Maximum value for an object of type short int 32767
USHRT_MAX Maximum value for an object of type unsigned short int 65535
INT_MIN Minimum value for an object of type int -32767
INT_MAX Maximum value for an object of type int 32767
UINT_MAX Maximum value for an object of type unsigned short int 65535
LONG_MIN Minimum value for an object of type long int -2147483647
LONG_MAX Maximum value for an object of type long int 2147483647
ULONG_MAX Maximum value for an object of type unsigned int 4294967295

示例:(mac air x86_64、Xcode)

#include <iostream>
#include <climits>

using namespace std;
int main(){
    cout<<CHAR_BIT<<endl;
    cout<<SCHAR_MIN<<endl;
    cout<<SCHAR_MAX<<endl;
    cout<<UCHAR_MAX<<endl;
    cout<<CHAR_MIN<<endl;
    cout<<CHAR_MAX<<endl;
    cout<<MB_LEN_MAX<<endl;
    cout<<SHRT_MIN<<endl;
    cout<<SHRT_MAX<<endl;
    cout<<USHRT_MAX<<endl;
    cout<<INT_MIN<<endl;
    cout<<INT_MAX<<endl;
    cout<<UINT_MAX<<endl;
    cout<<LONG_BIT<<endl;
    cout<<LONG_MIN<<endl;
    cout<<LONG_MAX<<endl;
    cout<<ULONG_MAX<<endl;
}

结果:

 

posted @ 2018-09-19 11:33  怪猫佐良  阅读(297)  评论(0编辑  收藏  举报