C/C++中各种类型int、long、double、char表示范围(最大最小值)

简介: 来源:http://blog.csdn.net/xuexiacm/article/details/8122267 1 #include 2 #include 3 #include 4 using namespace std; 5 6 int main(...

来源:http://blog.csdn.net/xuexiacm/article/details/8122267

 1 #include<iostream>  
 2 #include<string>  
 3 #include <limits>  
 4 using namespace std;  
 5       
 6 int main()  
 7 {  
 8     cout << "type: \t\t" << "************size**************"<< endl;  
 9     cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);  
10     cout << "\t最大值:" << (numeric_limits<bool>::max)();  
11     cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;  
12     cout << "char: \t\t" << "所占字节数:" << sizeof(char);  
13     cout << "\t最大值:" << (numeric_limits<char>::max)();  
14     cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;  
15     cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);  
16     cout << "\t最大值:" << (numeric_limits<signed char>::max)();  
17     cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;  
18     cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);  
19     cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();  
20     cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;  
21     cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);  
22     cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();  
23     cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;  
24     cout << "short: \t\t" << "所占字节数:" << sizeof(short);  
25     cout << "\t最大值:" << (numeric_limits<short>::max)();  
26     cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;  
27     cout << "int: \t\t" << "所占字节数:" << sizeof(int);  
28     cout << "\t最大值:" << (numeric_limits<int>::max)();  
29     cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;  
30     cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);  
31     cout << "\t最大值:" << (numeric_limits<unsigned>::max)();  
32     cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;  
33     cout << "long: \t\t" << "所占字节数:" << sizeof(long);  
34     cout << "\t最大值:" << (numeric_limits<long>::max)();  
35     cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;  
36     cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);  
37     cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();  
38     cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;  
39     cout << "double: \t" << "所占字节数:" << sizeof(double);  
40     cout << "\t最大值:" << (numeric_limits<double>::max)();  
41     cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;  
42     cout << "long double: \t" << "所占字节数:" << sizeof(long double);  
43     cout << "\t最大值:" << (numeric_limits<long double>::max)();  
44     cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;  
45     cout << "float: \t\t" << "所占字节数:" << sizeof(float);  
46     cout << "\t最大值:" << (numeric_limits<float>::max)();  
47     cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;  
48     cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);  
49     cout << "\t最大值:" << (numeric_limits<size_t>::max)();  
50     cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;  
51     cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;  
52     // << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;  
53     cout << "type: \t\t" << "************size**************"<< endl;  
54     return 0;  
55 }  
View Code

运算结果根据编译器的不同可能有不同结果。

 

相关文章
|
12月前
计算 long long, long double 字节大小
【10月更文挑战第14天】计算 long long, long double 字节大小
191 7
|
12月前
计算 long long, long double 字节大小
【10月更文挑战第13天】计算 long long, long double 字节大小。
137 4
|
12月前
|
存储 C语言
使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小
【10月更文挑战第13天】使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。
412 1
计算long long, long double 字节大小
计算long long, long double 字节大小。
215 3
|
存储 C语言
计算 int, float, double 和 char 字节大小
计算 int, float, double 和 char 字节大小。
209 3
|
存储 编译器 C++
C++从遗忘到入门问题之float、double 和 long double 之间的主要区别是什么
C++从遗忘到入门问题之float、double 和 long double 之间的主要区别是什么
191 0
详细解读C++char类型函数
详细解读C++char类型函数
215 0
|
存储 算法 物联网
int8与long long的深入对比与探讨
int8与long long的深入对比与探讨
|
存储 编译器 程序员
int 和 long 的区别
int 和 long 的区别
|
存储 Web App开发 编译器
C语言程序设计——int,double,char的用法
C语言程序设计——int,double,char的用法