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)
上一篇 2022年8月18日 上午10:16
下一篇 2022年8月18日 上午10:36


相关推荐

  • c++assert函数

    c++assert函数assert 宏的原型定义在 assert h 中 其作用是如果它的条件返回错误 则终止程序执行 include assert h assert intexpressio assert 的作用是先计算表达式 expression 如果其值为假 即为 0 那么它打印一条出错信息 然后通过调用 abort 来终止程序运行 如下图所示 include iostream include assert h usingnam assert h iostream assert h assert h

    2026年3月19日
    2
  • CSS filter属性详解

    CSS filter属性详解MDNfilter 介绍 filterCSS 属性将模糊或颜色偏移等图形效果应用于元素 滤镜通常用于调整图像 背景和边框的渲染 CSS 标准里包含了一些已实现预定义效果的函数 你也可以参考一个 SVG 滤镜 通过一个 URL 链接到 SVG 滤镜元素 SVGfilterele filter 定义的 10 种效果分别是 blur opacity grayscale sepia saturate hue

    2026年3月19日
    2
  • html页面导出为pdf(jsPDF、iText、wkhtmltopdf)「建议收藏」

    html页面导出为pdf(jsPDF、iText、wkhtmltopdf)「建议收藏」html页面导出pdf,本来是一件很简单的事情,在浏览器直接打印(Mac快捷键为⌘+p;Windows快捷键为ctrl+p),就可以把页面另存为pdf文件,但对于要经常把页面导出为pdf的用户来说并不友好。调研了几种html导出pdf的实现方式,这里把要点记录下来分享下。调研对象优点缺点分页图片表格链接中文特殊字符、样式导出…

    2022年6月8日
    42
  • 弧度和角度的转换_角度与弧度的换算表格

    弧度和角度的转换_角度与弧度的换算表格这两天在看同事写的四叉树代码,当中用到了孤度和角度之间的转换,所以转载此文章进行了学习2009-12-01弧度与角度的关系一、角的两种单位“弧度”和“度”是度量角大小的两种不同的单位。就像“米”和

    2022年8月4日
    10
  • 国密消息鉴别码学习笔记 ——含GB/T 15852和HMAC(第3章 采用HASH算法的MAC)

    国密消息鉴别码学习笔记 ——含GB/T 15852和HMAC(第3章 采用HASH算法的MAC)国密消息鉴别码 含 GB T15852 和 HMAC 摘要 本文档对我国标准规定的消息鉴别码的生成算法进行了简要介绍 包括算法生成步骤 注意事项等 我国的相关标准包括 GB T15852 1 2008 GB T15852 2 2012 GB T15852 3 目前为草稿 关键词 消息鉴别码 MAC HMAC 杂凑算法 哈希算法 HASH 分组密码 消息填充 3 基于专用杂

    2026年3月20日
    2
  • 漫谈并发编程(六):java中一些经常使用的并发构件的介绍[通俗易懂]

    漫谈并发编程(六):java中一些经常使用的并发构件的介绍

    2022年1月23日
    57

发表回复

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

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