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

常见的数据范围

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

一、总结

名称字节位数(二进制)最小值最大值位数(十进制)
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;
}


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

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

    分享给朋友:

    相关文章

    图的访问与遍历-深度优先搜索

    图的访问与遍历-深度优先搜索

    一、图的遍历图的遍历是指从图中的某个顶点出发,按照一定规则访问图中所有顶点且每个顶点仅访问一次的过程,核心分为深度优先搜索(DFS) 和广度优先搜索(BFS) 两大类,适用于无向图...

    【数据结构】栈的基本操作

    0.前言上一篇中简单介绍了栈的定义,这一篇中介绍栈的基本用法,包含压栈,出栈,判断栈空,判断栈中元素个数等。下面进行详细介绍1.基本用法本文介绍的栈的主要操作,使用栈之前加入<stack>...

    二维数组的差分

    一、基本概念二维数组差分是一种高效处理区间修改操作的数据结构技巧,常用于解决矩阵区域增减问题。差分是前缀和的逆运算,对于二维数组,差分数组 diff[i][j] 表示原数组 a[i][j] 与 a[i...

    【初级篇】函数(一)

    【初级篇】函数(一)

    0.函数的引入为什么要用函数呢?比较官方的说法是,过程的复用,你的一段逻辑,你有一段逻辑不断的在复用,就封装成函数去调用它。通俗的说法就是,把重复的过程集中到一块。例如,大家都学过如何求正方形的面积,...

    DEVC++如何支持C++11

    DEVC++如何支持C++11

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

    树的遍历

    在应用树结构解决问题时,往往要求按照某种此项获得树中全部结点的信息,这种操作叫做树的遍历。遍历的方法有很多种。常用的有:A. 先序遍历:先访问根结点,再从左到右按照先序思想遍历各子树。B. 后序遍历:...