C++的头文件中包含了符号常量,用来表示类型的限制。
下边列出一些常用的符号常量:
#include
#include
using namespace std;
int main()
{
cout << CHAR_BIT << endl; // char的位数
cout << CHAR_MAX << endl; // char的最大值
cout << CHAR_MIN << endl; // char的最小值
return 0;
}
/*****输出******/
8
127
-128
int有32为: -231 ~ 231-1
因为第一位是符号位,所以只有31位表示数值
#include
#include
using namespace std;
int main()
{
cout << INT_MAX << endl; // int的最大值
cout << INT_MIN << endl; // int的最小值
return 0;
}
/*****输出*****/
2147483647
-2147483648
在32位机器中,long表示4B ; 在64位机器中,long表示8B , 现在基本上都是64位机器
644位机器上的表示范围:-263 ~ 263 - 1
#include
#include
using namespace std;
int main()
{
cout << LONG_MAX << endl; // long的最大值
cout << LONG_MIN << endl; // long的最小值
cout << ULONG_MAX << endl; // unsigned long的最大值
return 0;
}
/*****输出*****/
9223372036854775807
-9223372036854775808
18446744073709551615
#include
#include
using namespace std;
int main()
{
cout << LLONG_MAX << endl; // long long的最大值
cout << LLONG_MIN << endl; // long long的最小值
return 0;
}
/*****输出*****/
9223372036854775807
-9223372036854775808