C++关键词(一)之基础类型
1 基础类型统计
关键字 |
数据类型 |
范围 |
备注 |
bool |
布尔值 |
[true,false] |
|
char |
有符号字符型 |
[-128,127] |
等价于signed char |
unsigned char |
无符号字符型 |
[0,255] |
|
short |
有符号短整型 |
[-32768,32767] |
等价于signed short |
unsigned short |
无符号的短整型 |
[0,65535] |
|
int |
有符号整型 |
[-2147483648,2147483647] |
等价于signed int |
unsigned int |
无符号整型 |
[0,4294967295] |
|
long |
有符号长整型 |
[-9223372036854775808,9223372036854775807] |
|
unsigned long |
无符号长整型 |
[0,18446744073709551615] |
|
long long |
有符号超长整型 |
[-9223372036854775808,9223372036854775807] |
|
unsigned long long |
无符号超长整型 |
[0,18446744073709551615] |
|
float |
单精度浮点型 |
[1.17549e-38,3.40282e+38] |
|
double |
双精度浮点型 |
[2.22507e-308,1.79769e+308] |
|
long double |
长浮点型 |
[3.3621e-4932,1.18973e+4932] |
|
2.测试代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include iostream>
#include limits.h>
#include limits>
int main(int argc,char * argv[])
{
//limit.h
std::cout << "--------------C Style---------------" <<std::endl;
std::cout << "bool :[" "true,false]" << std::endl;
std::cout << "signed char :[" << SCHAR_MIN << "," << SCHAR_MAX "]" <<std::endl;
std::cout << "unsigned char :[" << CHAR_MIN << "," << UCHAR_MAX "]" << std::endl;
std::cout << "short :[" << SHRT_MIN << "," <<SHRT_MAX "]" << std::endl;
std::cout << "unsigned short :[" << 0 << "," << USHRT_MAX "]" << std::endl;
std::cout << "int :[" << INT_MIN <<"," << INT_MAX "]" << std::endl;
std::cout<< "unsigned int :[" 0 "," << UINT_MAX <<"]" <<std::endl;
std::cout << "long :[" << LONG_MIN << "," << LONG_MAX << "]" << std::endl;
std::cout << "unsigned long :[" <<0 <<"," << ULONG_MAX << "]" << std::endl;
std::cout <<"long long :[" << LONG_LONG_MIN "," << LONG_LONG_MAX <<"]" <<std::endl;
std::cout <<"unsigned long long :[" << 0 <<"," <<ULONG_LONG_MAX <<"]"<< std::endl;
std::cout "--------------C++ Style---------------" std::endl;
std::cout "char :[" << int(std::numeric_limits char>::min()) << "," << int(std::numeric_limits <char>::max()) << "]" << std::endl;
std::cout "unsigned char :[" <<int(std::numeric_limits unsigned char>::min())<< ","<< int(std::numeric_limits <unsigned char>::max()) <<"]" << std::endl;
std::cout "short :[" << std::numeric_limits<short>::min() << "," << std::numeric_limits< short>::max() << "]" <<std::endl;
std::cout "unsigned short :[" << std::numeric_limits< unsigned short>::min() << "," << std::numeric_limits<unsigned short>::max()<< "]" << std::endl;
std::cout "int :[" << std::numeric_limits <int>::min()<< "," << std::numeric_limits <int>::max() <<"]"<< std::endl;
std::cout "unsigned int :[" << std::numeric_limits< unsigned int>::min() << "," << std::numeric_limits< unsigned int>::max() << "]" << std::endl;
std::cout "long :[" << std::numeric_limits< long>::min() << "," << std::numeric_limits <long>::max() << "]"<< std::endl;
std::cout "unsigned long :[" << std::numeric_limits< unsigned long>::min()<< "," << std::numeric_limits <unsigned long>::max() << "]" << std::endl;
std::cout "long long :[" << std::numeric_limits <long long>::min() << "," << std::numeric_limits <long long>::max() << "]" << std::endl;
std::cout "unsigned long long:["<< std::numeric_limits< unsigned long long>::min() << "," << std::numeric_limits <unsigned long long>::max() << "]" << std::endl;
std::cout "float :[" << std::numeric_limits <float>::min() << "," <<std::numeric_limits< float>::max() << "]"<< std::endl;
std::cout "double :[" << std::numeric_limits <double>::min()<< "," <<std::numeric_limits< double>::max() << "]" << std::endl;
std::cout "long double :[" << std::numeric_limits <long double>::min() << "," << std::numeric_limits <long double>::max() << "]" << std::endl;
return 0;
}
|
3.程序输出
--------------C Style---------------
bool :[true,false]
signed char :[-128,127]
unsigned char :[0,255]
short :[-32768,32767]
unsigned short :[0,65535]
int :[-2147483648,2147483647]
unsigned int :[0,4294967295]
long :[-9223372036854775808,9223372036854775807]
unsigned long :[0,18446744073709551615]
long long :[-9223372036854775808,9223372036854775807]
unsigned long long :[0,18446744073709551615]
--------------C++ Style---------------
char :[-128,127]
unsigned char :[0,255]
short :[-32768,32767]
unsigned short :[0,65535]
int :[-2147483648,2147483647]
unsigned int :[0,4294967295]
long :[-9223372036854775808,9223372036854775807]
unsigned long :[0,18446744073709551615]
long long :[-9223372036854775808,9223372036854775807]
unsigned long long:[0,18446744073709551615]
float :[1.17549e-38,3.40282e+38]
double :[2.22507e-308,1.79769e+308]
long double :[3.3621e-4932,1.18973e+4932]