首页 > 编程语言 > 详细

C++中各种基本数据类型大小一览

时间:2020-08-11 22:09:33      阅读:75      评论:0      收藏:0      [点我收藏+]

??10^9以下用int10^18以下用long long

??C++代码如下

#include<iostream>
#include<string>
#include <limits>
using namespace std;

int main()
{
    cout << "type: \t\t\t" << "************size**************" << endl;
    cout << "bool: \t\t\t" << "numOfBytes:" << sizeof(bool);
    cout << "\t\tmaxValue:" << (numeric_limits<bool>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<bool>::min)() << endl;

    cout << "char: \t\t\t" << "numOfBytes:" << sizeof(char);
    cout << "\t\tmaxValue:" << (numeric_limits<char>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<char>::min)() << endl;

    cout << "signed char: \t\t" << "numOfBytes:" << sizeof(signed char);
    cout << "\t\tmaxValue:" << (numeric_limits<signed char>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<signed char>::min)() << endl;

    cout << "unsigned char: \t\t" << "numOfBytes:" << sizeof(unsigned char);
    cout << "\t\tmaxValue:" << (numeric_limits<unsigned char>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<unsigned char>::min)() << endl;

    cout << "wchar_t: \t\t" << "numOfBytes:" << sizeof(wchar_t);
    cout << "\t\tmaxValue:" << (numeric_limits<wchar_t>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<wchar_t>::min)() << endl;

    cout << "short: \t\t\t" << "numOfBytes:" << sizeof(short);
    cout << "\t\tmaxValue:" << (numeric_limits<short>::max)();
    cout << "\t\t\t\tminValue:" << (numeric_limits<short>::min)() << endl;

    cout << "int: \t\t\t" << "numOfBytes:" << sizeof(int);
    cout << "\t\tmaxValue:" << (numeric_limits<int>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<int>::min)() << endl;

    cout << "unsigned: \t\t" << "numOfBytes:" << sizeof(unsigned);
    cout << "\t\tmaxValue:" << (numeric_limits<unsigned>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<unsigned>::min)() << endl;

    cout << "long: \t\t\t" << "numOfBytes:" << sizeof(long);
    cout << "\t\tmaxValue:" << (numeric_limits<long>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<long>::min)() << endl;

    cout << "long long: \t\t" << "numOfBytes:" << sizeof(long long);
    cout << "\t\tmaxValue:" << (numeric_limits<long long>::max)();
    cout << "\t\tminValue:" << (numeric_limits<long long>::min)() << endl;

    cout << "unsigned long: \t\t" << "numOfBytes:" << sizeof(unsigned long);
    cout << "\t\tmaxValue:" << (numeric_limits<unsigned long>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<unsigned long>::min)() << endl;

    cout << "double: \t\t" << "numOfBytes:" << sizeof(double);
    cout << "\t\tmaxValue:" << (numeric_limits<double>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<double>::min)() << endl;

    cout << "long double: \t\t" << "numOfBytes:" << sizeof(long double);
    cout << "\t\tmaxValue:" << (numeric_limits<long double>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<long double>::min)() << endl;

    cout << "float: \t\t\t" << "numOfBytes:" << sizeof(float);
    cout << "\t\tmaxValue:" << (numeric_limits<float>::max)();
    cout << "\t\t\tminValue:" << (numeric_limits<float>::min)() << endl;

    cout << "size_t: \t\t" << "numOfBytes:" << sizeof(size_t);
    cout << "\t\tmaxValue:" << (numeric_limits<size_t>::max)();
    cout << "\t\tminValue:" << (numeric_limits<size_t>::min)() << endl;

    cout << "\t\t\t" << "************size**************" << endl;
    return 0;
}

技术分享图片

C++中各种基本数据类型大小一览

原文:https://www.cnblogs.com/flyingrun/p/13485201.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!