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

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

 

相关文章
|
存储 算法 安全
c++模板进阶操作——非类型模板参数、模板的特化以及模板的分离编译
在 C++ 中,仿函数(Functor)是指重载了函数调用运算符()的对象。仿函数可以像普通函数一样被调用,但它们实际上是对象,可以携带状态并具有更多功能。与普通函数相比,仿函数具有更强的灵活性和可扩展性。仿函数通常通过定义一个包含operator()的类来实现。public:// 重载函数调用运算符Add add;// 创建 Add 类的对象// 使用仿函数return 0;
481 0
|
存储 编译器 程序员
C++类型参数化
【10月更文挑战第1天】在 C++ 中,模板是实现类型参数化的主要工具,用于编写能处理多种数据类型的代码。模板分为函数模板和类模板。函数模板以 `template` 关键字定义,允许使用任意类型参数 `T`,并在调用时自动推导具体类型。类模板则定义泛型类,如动态数组,可在实例化时指定具体类型。模板还支持特化,为特定类型提供定制实现。模板在编译时实例化,需放置在头文件中以确保编译器可见。
377 12
|
存储 C语言
使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小
【10月更文挑战第13天】使用 sizeof 操作符计算int, float, double 和 char四种变量字节大小。
981 1
|
安全 程序员 C语言
C++(四)类型强转
本文详细介绍了C++中的四种类型强制转换:`static_cast`、`reinterpret_cast`、`const_cast`和`dynamic_cast`。每种转换都有其特定用途和适用场景,如`static_cast`用于相关类型间的显式转换,`reinterpret_cast`用于低层内存布局操作,`const_cast`用于添加或移除`const`限定符,而`dynamic_cast`则用于运行时的类型检查和转换。通过具体示例展示了如何正确使用这四种转换操作符,帮助开发者更好地理解和掌握C++中的类型转换机制。
|
C++
使用 QML 类型系统注册 C++ 类型
使用 QML 类型系统注册 C++ 类型
878 0
|
存储 C++
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
【C/C++学习笔记】string 类型的输入操作符和 getline 函数分别如何处理空白字符
584 0
|
编译器 C++ 开发者
【C++篇】深度解析类与对象(下)
在上一篇博客中,我们学习了C++的基础类与对象概念,包括类的定义、对象的使用和构造函数的作用。在这一篇,我们将深入探讨C++类的一些重要特性,如构造函数的高级用法、类型转换、static成员、友元、内部类、匿名对象,以及对象拷贝优化等。这些内容可以帮助你更好地理解和应用面向对象编程的核心理念,提升代码的健壮性、灵活性和可维护性。
|
编译器 C++ 容器
【c++11】c++11新特性(上)(列表初始化、右值引用和移动语义、类的新默认成员函数、lambda表达式)
C++11为C++带来了革命性变化,引入了列表初始化、右值引用、移动语义、类的新默认成员函数和lambda表达式等特性。列表初始化统一了对象初始化方式,initializer_list简化了容器多元素初始化;右值引用和移动语义优化了资源管理,减少拷贝开销;类新增移动构造和移动赋值函数提升性能;lambda表达式提供匿名函数对象,增强代码简洁性和灵活性。这些特性共同推动了现代C++编程的发展,提升了开发效率与程序性能。
758 12
|
编译器 C语言 C++
类和对象的简述(c++篇)
类和对象的简述(c++篇)
|
设计模式 安全 C++
【C++进阶】特殊类设计 && 单例模式
通过对特殊类设计和单例模式的深入探讨,我们可以更好地设计和实现复杂的C++程序。特殊类设计提高了代码的安全性和可维护性,而单例模式则确保类的唯一实例性和全局访问性。理解并掌握这些高级设计技巧,对于提升C++编程水平至关重要。
416 16