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


  109**以下用`int`,**1018以下用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;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM