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