C++学习——int、long、long long, double, long double等的占用空间及取值范围「建议收藏」

C++学习——int、long、long long, double, long double等的占用空间及取值范围「建议收藏」unsigned int 0~4294967295int 2147483648~2147483647unsigned long 0~4294967295long 2147483648~2147483647long long的最大值:9223372036854775807long long的最小值:-9223372036854775808unsigned long lon…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

unsigned int 0~4294967295

int 2147483648~2147483647
unsigned long 0~4294967295
long 2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161

__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615

#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;  
}

输出结果为:
在这里插入图片描述

注意:

一字节表示八位,即:1byte = 8 bit;

int: 4byte = 32 bit 有符号signed范围:2^31-1 ~ -2^31即:2147483647 ~ -2147483648无符号unsigned范围:2^32-1 ~ 0即:4294967295 ~ 0

long: 4 byte = 32 bit 同int型

double: 8 byte = 64 bit 范围:1.79769e+308 ~ 2.22507e-308

long double: 12 byte = 96 bit 范围: 1.18973e+4932 ~ 3.3621e-4932

float: 4 byte = 32 bit 范围: 3.40282e+038 ~ 1.17549e-038

int、unsigned、long、unsigned long 、double的数量级最大都只能表示为10亿,即它们表示十进制的位数不超过10个,即可以保存所有9位整数。而short只是能表示5位;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/170956.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 主、外键约束_创建主键约束

    主、外键约束_创建主键约束主、外键约束点关注不迷路,欢迎再来!主键和外键是两种类型的约束;1.主键是能唯一的标识表中的每一行,就是说这一列非空且值不重复,可以指定为主键;作用是用来强制约束表中的每一行数据的唯一性;2.外键是b表中的某一列引用的值来源于a表中的主键列。也是约束b表中的外键列的值必须取致a表中的主键列值,不是其中的值就不能插入b表中。可以形成a表b表的联系,保持数据的约束和关联性。创建主表主键…

    2022年10月20日
    0
  • 超详细的springBoot学习笔记

    超详细的springBoot学习笔记SpringBoot1.SpringBoot简介Spring诞生时是Java企业版(JavaEnterpriseEdition,JEE,也称J2EE)的轻量级代替品。无需开发重量级的EnterpriseJavaBean(EJB),Spring为企业级Java开发提供了一种相…

    2022年10月21日
    0
  • pycharm 编码怎么设置_pycharm编码格式

    pycharm 编码怎么设置_pycharm编码格式Python中默认的编码格式是ASCII格式,在没修改编码格式时无法正确打印汉字,所以在读取中文时会报错。有两种解决方法。一种是在python的编程工具Pycharm中设置默认编码pycharm下载地址:http://www.jetbrains.com/pycharm/选择社区版即可,免费。设置方法如下:入口A:工具栏-File-DefaultSettings-Editor-File…

    2022年8月27日
    3
  • Java设计模式(八)之结构型模式:代理模式

    Java设计模式(八)之结构型模式:代理模式

    2021年4月9日
    144
  • vim命令复制粘贴命令_linux编辑文件命令vim

    vim命令复制粘贴命令_linux编辑文件命令vim今天被vim的复制粘贴弄得很烦,它不像windows那样,每次复制会把以前的内容覆盖。所以有时粘贴出来的东西并不是你想要的。在不同终端中,用vim打开的两个文件之间的复制粘贴1.用同一个终端,直接使用这个命令:vimfile1file2这样就可以直接用y和p复制粘贴了。但是这样比较麻烦,需要在两个文件之间切换。2.之所以不能直接用y和p复制粘贴。是因为每个终端中的vim复制的内容存储在不同…

    2022年9月22日
    0
  • django csdn_django queryset合并

    django csdn_django queryset合并前言cookie:在网站中,http请求是无状态的。也就是说即使第一次和服务器连接后并且登录成功后,第二次请求服务器依然不能知道当前请求是哪个用户。cookie的出现就是为了解决这个问题,第一次登录

    2022年7月31日
    6

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号