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

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

 

相关文章
|
17天前
|
存储 算法 安全
c++模板进阶操作——非类型模板参数、模板的特化以及模板的分离编译
在 C++ 中,仿函数(Functor)是指重载了函数调用运算符()的对象。仿函数可以像普通函数一样被调用,但它们实际上是对象,可以携带状态并具有更多功能。与普通函数相比,仿函数具有更强的灵活性和可扩展性。仿函数通常通过定义一个包含operator()的类来实现。public:// 重载函数调用运算符Add add;// 创建 Add 类的对象// 使用仿函数return 0;
|
7月前
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
90 3
|
7月前
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
173 2
|
8月前
|
存储 编译器 程序员
C++类型参数化
【10月更文挑战第1天】在 C++ 中,模板是实现类型参数化的主要工具,用于编写能处理多种数据类型的代码。模板分为函数模板和类模板。函数模板以 `template` 关键字定义,允许使用任意类型参数 `T`,并在调用时自动推导具体类型。类模板则定义泛型类,如动态数组,可在实例化时指定具体类型。模板还支持特化,为特定类型提供定制实现。模板在编译时实例化,需放置在头文件中以确保编译器可见。
96 11
|
7月前
|
编译器 C#
c# - 运算符<<不能应用于long和long类型的操作数
在C#中,左移运算符的第二个操作数必须是 `int`类型,因此需要将 `long`类型的位移计数显式转换为 `int`类型。这种转换需要注意数据丢失和负值处理的问题。通过本文的详细说明和示例代码,相信可以帮助你在实际开发中正确使用左移运算符。
62 0
|
9月前
|
安全 程序员 C语言
C++(四)类型强转
本文详细介绍了C++中的四种类型强制转换:`static_cast`、`reinterpret_cast`、`const_cast`和`dynamic_cast`。每种转换都有其特定用途和适用场景,如`static_cast`用于相关类型间的显式转换,`reinterpret_cast`用于低层内存布局操作,`const_cast`用于添加或移除`const`限定符,而`dynamic_cast`则用于运行时的类型检查和转换。通过具体示例展示了如何正确使用这四种转换操作符,帮助开发者更好地理解和掌握C++中的类型转换机制。
|
10月前
|
C++
使用 QML 类型系统注册 C++ 类型
使用 QML 类型系统注册 C++ 类型
282 0
|
10月前
|
存储 C++
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
150 0
|
存储 Java
百度搜索:蓝易云【Java语言之float、double内存存储方式】
由于使用IEEE 754标准进行存储,float和double类型可以表示非常大或非常小的浮点数,并且具有一定的精度。然而,由于浮点数的特性,它们在进行精确计算时可能会存在舍入误差。在编写Java程序时,需要注意使
138 0
|
6月前
|
存储 关系型数据库 MySQL
double ,FLOAT还是double(m,n)--深入解析MySQL数据库中双精度浮点数的使用
本文探讨了在MySQL中使用`float`和`double`时指定精度和刻度的影响。对于`float`,指定精度会影响存储大小:0-23位使用4字节单精度存储,24-53位使用8字节双精度存储。而对于`double`,指定精度和刻度对存储空间没有影响,但可以限制数值的输入范围,提高数据的规范性和业务意义。从性能角度看,`float`和`double`的区别不大,但在存储空间和数据输入方面,指定精度和刻度有助于优化和约束。
1063 5

热门文章

最新文章