C++各种数据类型表示范围

简介: 转自:http://www.cnblogs.com/maowang1991/p/3166928.html #include <iostream>#include <string>#include <limits>using namespace std;int main(){ cout << "type: \t\t" &lt

转自:http://www.cnblogs.com/maowang1991/p/3166928.html

#include <iostream>
#include <string>
#include <limits>
using namespace std;

int main()
{
	cout << "type: \t\t" << "************size**************"<< endl;
	cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
	cout << "\t最大值:" << (numeric_limits<bool>::max)();
	cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
	cout << "char: \t\t" << "所占字节数:" << sizeof(char);
	cout << "\t最大值:" << (numeric_limits<char>::max)();
	cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;
	cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
	cout << "\t最大值:" << (numeric_limits<signed char>::max)();
	cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;
	cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
	cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();
	cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;
	cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
	cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();
	cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;
	cout << "short: \t\t" << "所占字节数:" << sizeof(short);
	cout << "\t最大值:" << (numeric_limits<short>::max)();
	cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;
	cout << "int: \t\t" << "所占字节数:" << sizeof(int);
	cout << "\t最大值:" << (numeric_limits<int>::max)();
	cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;
	cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
	cout << "\t最大值:" << (numeric_limits<unsigned>::max)();
	cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;
	cout << "long: \t\t" << "所占字节数:" << sizeof(long);
	cout << "\t最大值:" << (numeric_limits<long>::max)();
	cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;
	cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
	cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();
	cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;
	cout << "double: \t" << "所占字节数:" << sizeof(double);
	cout << "\t最大值:" << (numeric_limits<double>::max)();
	cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;
	cout << "long double: \t" << "所占字节数:" << sizeof(long double);
	cout << "\t最大值:" << (numeric_limits<long double>::max)();
	cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;
	cout << "float: \t\t" << "所占字节数:" << sizeof(float);
	cout << "\t最大值:" << (numeric_limits<float>::max)();
	cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;
	cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
	cout << "\t最大值:" << (numeric_limits<size_t>::max)();
	cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;
	cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
	// << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;
	cout << "type: \t\t" << "************size**************"<< endl;
	return 0;
}


目录
相关文章
|
5月前
|
存储 安全 C++
C++ 用户输入与数据类型详解:建立基本计算器及变量类型
了解C++的用户输入和数据类型。使用`cin`从键盘读取数据,如在简单计算器示例中获取两个数字并求和。C++的数据类型包括:`int`(整数)、`float`(浮点数,约6-7位小数)、`double`(更精确的浮点数,约15位小数)、`bool`(布尔值,true或false)、`char`(单个字符)和`string`(文本字符串)。每种类型都有特定的存储大小和用途。在处理浮点数时,`double`通常更安全。字符串需要包含`&lt;string&gt;`库。更多内容可关注微信公众号`Let us Coding`获取。
72 0
|
5月前
|
存储 安全 编译器
C++系列二:数据类型
C++系列二:数据类型
|
5月前
|
存储 程序员 C++
C++数据类型
C++数据类型
40 2
|
9天前
|
存储 Linux C语言
【C++基础】数据类型详解
这篇文章详细介绍了C++中各种基本数据类型,包括整型、浮点型、字符型、字符串型和布尔型,以及它们的使用方式和范围。
14 4
|
4月前
|
Java API C++
Java JNI开发时常用数据类型与C++中数据类型转换
Java JNI开发时常用数据类型与C++中数据类型转换
152 0
|
2月前
|
C++
c++学习笔记01 基本知识与数据类型
C++学习笔记,涵盖了C++中的常量定义、数据类型、变量内存大小计算、基本数据类型(整型、实型、字符型、字符串型、布尔型)以及转义字符的使用。
42 4
|
4月前
|
存储 C++ 容器
C++一分钟之-变量与数据类型入门
【6月更文挑战第18天】**C++编程基础:变量与数据类型概览** 了解变量(存储数据的容器)和数据类型是编程入门的关键。声明变量如`int age = 25;`,注意初始化和类型匹配。基本数据类型包括整型(int等)、浮点型(float、double)、字符型(char)和布尔型(bool)。理解类型范围和精度,使用字面量后缀增强可读性。深入学习数组、指针、结构体和类,以及动态内存管理,避免数组越界和内存泄漏。不断实践以巩固理论知识。
37 1
|
4月前
|
数据安全/隐私保护 C++
C++ 中的类是一种用户定义的数据类型,用于表示具有相似特征和行为的对象的模板。
C++ 中的类是一种用户定义的数据类型,用于表示具有相似特征和行为的对象的模板。
|
3月前
|
存储 编译器 C++
|
4月前
|
C语言 C++
技术经验分享:c++中的数据类型转换
技术经验分享:c++中的数据类型转换
19 0