C/C++ 基本数据类型的范围

一、常见的数据类型及其范围

数据类型 Size(64位) 范围
int 4Byte -2\times 10^{10}\sim 2\times10^{10}
unsigned int 4Byte 0\sim4\times 10^{10}
long 4Byte -2\times 10^{10}\sim 2\times10^{10}
unsigned long 4Byte 0\sim4\times 10^{10}
long long 8Byte -0.9\times 10^{20}\sim 0.9\times 10^{20}
unsigned long long 8Byte 0\sim 1.8\times 10^{20}

查询Size代码:sizeof(类型)

查询范围代码:numeric_limits<类型>::maxnumeric_limits<类型>::min

#include
#include
#include 
using namespace std; 
int main()
{
    cout << "type: \t\t" << "************size**************"<< endl;
    cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "char: \t\t" << "所占字节数:" << sizeof(char);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "short: \t\t" << "所占字节数:" << sizeof(short);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t\t最小值:" << (numeric_limits::min)() << endl;
    cout << "int: \t\t" << "所占字节数:" << sizeof(int);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "long: \t\t" << "所占字节数:" << sizeof(long);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "double: \t" << "所占字节数:" << sizeof(double);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "long double: \t" << "所占字节数:" << sizeof(long double);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "float: \t\t" << "所占字节数:" << sizeof(float);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
    cout << "\t最大值:" << (numeric_limits::max)();
    cout << "\t最小值:" << (numeric_limits::min)() << endl;
    cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
    cout << "type: \t\t" << "************size**************"<< endl;
    return 0;
}

二、常用的ASCII表

C/C++ 基本数据类型的范围_第1张图片

你可能感兴趣的:(C/C++,c++,开发语言)