当前位置:首页 > C++目录 > 正文内容

常见的数据范围

亿万年的星光3年前 (2022-10-07)C++目录2318

一、总结

名称字节位数(二进制)最小值最大值位数(十进制)
bool
1
801
1
char18


shrot 
216    (-2^15  到2^15  -1)-32768327675
int4
32    (-2^31 到 2^31  -1)-21474836482147483647 10
unsigned int 4320429496729510
long
432-2147483648214748364710
long long 864
-9223372036854775808922337203685477580719
float
4321.17549e-0383.40282e+038
double8
642.22507e-3081.79769e+308
string864


二、测试代码

#include<iostream>  
#include<string>  
#include <limits>  
using namespace std;
 
int main()
{
	cout << "type:\t\t" << "---size---" << endl;
	
	cout << "bool:\t\t" << "所占字节数:" << sizeof(bool)
		<< "\t位数:" << sizeof(bool)*8
		<< "\t\t最小值:" << (numeric_limits<bool>::min)() 
		<< "\t\t最大值:" << (numeric_limits<bool>::max)() << endl << endl;
	
	cout << "char:\t\t" << "所占字节数:" << sizeof(char)
		<< "\t位数:" << sizeof(char) * 8
		<< "\t\t最小值:" << (numeric_limits<char>::min)()
		<< "\t\t最大值:" << (numeric_limits<char>::max)() << endl << endl;
	
	cout << "signed char:\t" << "所占字节数:" << sizeof(signed char)
		<< "\t位数:" << sizeof(signed char) * 8
		<< "\t\t最小值:" << (numeric_limits<signed char>::min)()
		<< "\t\t最大值:" << (numeric_limits<signed char>::max)() << endl << endl;
	
	cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char)
		<< "\t位数:" << sizeof(unsigned char) * 8
		<< "\t\t最小值:" << (numeric_limits<unsigned char>::min)()
		<< "\t\t最大值:" << (numeric_limits<unsigned char>::max)() << endl << endl;
	
	cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t)
		<< "\t位数:" << sizeof(wchar_t) * 8
		<< "\t最小值:" << (numeric_limits<wchar_t>::min)()
		<< "\t\t最大值:" << (numeric_limits<wchar_t>::max)() << endl << endl;
	
	cout << "short: \t\t" << "所占字节数:" << sizeof(short)
		<< "\t位数:" << sizeof(short) * 8
		<< "\t最小值:" << (numeric_limits<short>::min)()
		<< "\t\t最大值:" << (numeric_limits<short>::max)() << endl << endl;
	
	cout << "int: \t\t" << "所占字节数:" << sizeof(int)
		<< "\t位数:" << sizeof(int) * 8
		<< "\t最小值:" << (numeric_limits<int>::min)()
		<< "\t最大值:" << (numeric_limits<int>::max)() << endl << endl;
	
	cout << "unsigned int: \t" << "所占字节数:" << sizeof(unsigned)
		<< "\t位数:" << sizeof(unsigned) * 8
		<< "\t最小值:" << (numeric_limits<unsigned>::min)()
		<< "\t\t最大值:" << (numeric_limits<unsigned>::max)() << endl << endl;
	
	cout << "long: \t\t" << "所占字节数:" << sizeof(long)
		<< "\t位数:" << sizeof(long) * 8
		<< "\t最小值:" << (numeric_limits<long>::min)()
		<< "\t最大值:" << (numeric_limits<long>::max)() << endl << endl;
	
	cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long)
		<< "\t位数:" << sizeof(unsigned long) * 8
		<< "\t最小值:" << (numeric_limits<unsigned long>::min)()
		<< "\t\t最大值:" << (numeric_limits<unsigned long>::max)() << endl << endl;
 
	cout << "float: \t\t" << "所占字节数:" << sizeof(float)
		<< "\t位数:" << sizeof(float) * 8
		<< "\t最小值:" << (numeric_limits<float>::min)() 
		<< "\t最大值:" << (numeric_limits<float>::max)() << endl << endl;
		
	cout << "double: \t" << "所占字节数:" << sizeof(double)
		<< "\t位数:" << sizeof(double) * 8
		<< "\t最小值:" << (numeric_limits<double>::min)()
		<< "\t最大值:" << (numeric_limits<double>::max)() << endl << endl;
	
	cout << "size_t: \t" << "所占字节数:" << sizeof(size_t)
		<< "\t位数:" << sizeof(size_t) * 8
		<< "\t最小值:" << (numeric_limits<size_t>::min)()
		<< "\t\t最大值:" << (numeric_limits<size_t>::max)() << endl << endl;
	
	cout << "string: \t" << "所占字节数:" << sizeof(string)
		<< "\t位数:" << sizeof(string) * 8 << endl;
		
		cout << "long long: \t" << "所占字节数:" << sizeof(long long)
		<< "\t位数:" << sizeof(long long) * 8
		<< "\t最小值:" << (numeric_limits<long long>::min)()
		<< "\t\t最大值:" << (numeric_limits<long long>::max)() << endl << endl;	
	
	system("pause");
	return 0;
}


扫描二维码推送至手机访问。

版权声明:本文由青少年编程知识记录发布,如需转载请注明出处。

分享给朋友:

相关文章

01背包问题

问题定义01背包问题是一个经典的组合优化问题,通常描述如下:有个容量为C的背包有n件物品,第i件物品的重量为Wi,价值为Vi每种物品只有一件,可以选择放入背包(1)或不放入背包(0),因此称为“01”...

C++中双冒号(::)的用法

一、作用域符号前面一般是类名称,后面一般是该类的成员名称,C++为例避免不同的类有名称相同的成员而采用作用域的方式进行区分如:A,B表示两个类,在A,B中都有成员member。那么A::member就...

CSP-J2021年普及组复赛T4——小熊的果篮

【题目描述】    小熊的水果店里摆放着一排 n 个水果。每个水果只可能是苹果或桔子,从左到右依 次用正整数 1、2、3、……、n 编号。连续排在一起的同一种...

DEVC++如何支持C++11

DEVC++如何支持C++11

DEVC++默认开启C++11,需要手动添加C++11支持。DEVC++需要使用高一点的版本,DEVC++5.11下载地址:(1)  官方下载地址: Dev-C++ downloa...

2021 年青岛市程序设计竞赛试题(小学组)决赛

2021 年青岛市程序设计竞赛试题(小学组)决赛

1.方程求解【描述】输入正整数 a,b,c。求有多少组 x 和 y 满足 a*x+b*y=c 。x 和 y 都是非负整数。【输入】一行,包含三个正整数 a,b,c,两个整数之间用单个空格隔开。【输出】...

树的存储与遍历—链式存储

一、定义链式存储是表示树结构最直观、最常用的一种方法。它的核心思想是:用链表中的节点来表示树中的每个元素。每个节点不仅包含数据本身,还包含指向其子节点的指针。二、基本结构对于一个普通的树(不一定是二叉...