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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • kali 换源教程

    一·寻找终端kali的终端类似于windows的dos,可以在此界面中,对kali系统进行操纵。其位于界面左侧,第三个图标便是终端。二·打开“sources.list“打开kali的终端输入命令“leafpad/etc/apt/sources.list“三·更改“sources.list“界面里所有内容全部删除,添加中科大的源。下面的就是中科大源的地址。debhttps:…

    2022年4月9日
  • shell中的if判断语句怎么写_shell脚本中if用法

    shell中的if判断语句怎么写_shell脚本中if用法if条件判断与if真假判断目录:1.正确写法2.错误写法3.总结一、正确写法在编写shell脚本时,为简化代码的行号及结构的简约型,通常将命令执行结果和判断通过一条语句进行编写(在C语言编写程序时,经常遇到此种写法),如:方法1:单一命令条件判断[root@centos7~]#touchtest.shifuseraddroot&am…

    2022年8月18日
  • 正确姿势临时和永久开启关闭Android的SELinux

    正确姿势临时和永久开启关闭Android的SELinux      正确姿势临时和永久关闭Android的SELinux前言  自从Android4.4强制开启SELinux以后,在开发中我们经常会遇到avcdenied的问题,为了方便开发调试我们会将SELinux关闭,那么本章将带领读者怎么临时和永久关闭Android的SELinux。正确姿势临时和永久关闭Android的SELinux1.1临时关闭Andro…

    2022年6月27日
  • Oracle中的MONTHS_BETWEEN函数

    Oracle中的MONTHS_BETWEEN函数Syntax:MONTHS_BETWEEN(date1,date2)Purpose:返回两个日期之间的月份数1.如果date1>date2,则返回一个正数;2.如果date1<date2,则返回一个负数;3.如果date1=date2,则返回一个整数0;MONTHS_BETWEENreturnsnumberofmonthsbetweendates…

    2022年7月13日
  • Linux安装gcc方法(超简单安装)

    Linux安装gcc方法(超简单安装)Linux安装gcc方法(超简单安装)**1:Centos版本**终端输入以下命令yum-yinstallgccgcc-c++autoconfpcrepcre-develmakeautomakeyum-yinstallwgethttpd-toolsvim**2:Ubuntu版本**终端输入以下命令sudoaptinstallgcc输入Y开始安装获取版本信息,检查gcc是否安装成功了gcc–version出现版本信息代表安装完成*

    2022年5月25日
  • ie浏览器无法连接到代理服务器_网页无法连接到代理服务器

    ie浏览器无法连接到代理服务器_网页无法连接到代理服务器由于工作上的需要,相信很多用户会使用IE代理服务器,但是在设置之后遇到IE代理服务器没有响应错误提示(如图所示),并且浏览器无法打开网页的问题,但使用其他浏览器是可以正常上网,出现这种情况很有可能是注册表设置问题,我们可以按照以下方式来解决。     1、打开运行窗口(系统键Win+R),输入”regedit.exe”.如下图所示,根据下边的地址逐步打开:HKE

    2022年10月23日

发表回复

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

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