• c++各种数据类型表示范围


    符号属性     长度属性     基本型     所占位数     取值范围       输入符举例      输出符举例

    --            --          char         8         -2^7 ~ 2^7-1        %c          %c、%d、%u
    signed        --          char         8         -2^7 ~ 2^7-1        %c          %c、%d、%u
    unsigned      --          char         8         0 ~ 2^8-1           %c          %c、%d、%u

    [signed]      short       [int]        16        -2^15 ~ 2^15-1              %hd
    unsigned      short       [int]        16        0 ~ 2^16-1             %hu、%ho、%hx

    [signed]      --           int         32        -2^31 ~ 2^31-1              %d
    unsigned      --          [int]        32        0 ~ 2^32-1              %u、%o、%x

    [signed]      long        [int]        32        -2^31 ~ 2^31-1              %ld
    unsigned      long        [int]        32        0 ~ 2^32-1             %lu、%lo、%lx

    [signed]      long long   [int]        64        -2^63 ~ 2^63-1             %I64d
    unsigned      long long   [int]        64        0 ~ 2^64-1          %I64u、%I64o、%I64x

    --            --          float        32       +/- 3.40282e+038         %f、%e、%g
    --            --          double       64       +/- 1.79769e+308 %lf、%le、%lg   %f、%e、%g
    --            long        double       96       +/- 1.79769e+308        %Lf、%Le、%Lg

    #include<iostream>
    #include <limits>
    using namespace std;
    
    int main()
    {
    	//bool
    	cout << "bool: 		" << "所占字节数:" << sizeof(bool);
    	cout << "	最大值:" << (numeric_limits<bool>::max)();
    	cout << "		最小值:" << (numeric_limits<bool>::min)() << endl;
    	//char
    	cout << "char: 		" << "所占字节数:" << sizeof(char);
    	cout << "	最大值:" << (numeric_limits<char>::max)();
    	cout << "		最小值:" << (numeric_limits<char>::min)() << endl;
    	//signed char
    	cout << "signed char: 	" << "所占字节数:" << sizeof(signed char);
    	cout << "	最大值:" << (numeric_limits<signed char>::max)();
    	cout << "		最小值:" << (numeric_limits<signed char>::min)() << endl;
    	//unsigned char
    	cout << "unsigned char: 	" << "所占字节数:" << sizeof(unsigned char);
    	cout << "	最大值:" << (numeric_limits<unsigned char>::max)();
    	cout << "		最小值:" << (numeric_limits<unsigned char>::min)() << endl;
    	//wchar_t
    	cout << "wchar_t: 	" << "所占字节数:" << sizeof(wchar_t);
    	cout << "	最大值:" << (numeric_limits<wchar_t>::max)();
    	cout << "		最小值:" << (numeric_limits<wchar_t>::min)() << endl;
    	//short
    	cout << "short: 		" << "所占字节数:" << sizeof(short);
    	cout << "	最大值:" << (numeric_limits<short>::max)();
    	cout << "		最小值:" << (numeric_limits<short>::min)() << endl;
    	//int
    	cout << "int: 		" << "所占字节数:" << sizeof(int);
    	cout << "	最大值:" << (numeric_limits<int>::max)();
    	cout << "	最小值:" << (numeric_limits<int>::min)() << endl;
    	//unsigned
    	cout << "unsigned: 	" << "所占字节数:" << sizeof(unsigned);
    	cout << "	最大值:" << (numeric_limits<unsigned>::max)();
    	cout << "	最小值:" << (numeric_limits<unsigned>::min)() << endl;
    	//long
    	cout << "long: 		" << "所占字节数:" << sizeof(long);
    	cout << "	最大值:" << (numeric_limits<long>::max)();
    	cout << "	最小值:" << (numeric_limits<long>::min)() << endl;
    	//unsigned long
    	cout << "unsigned long: 	" << "所占字节数:" << sizeof(unsigned long);
    	cout << "	最大值:" << (numeric_limits<unsigned long>::max)();
    	cout << "	最小值:" << (numeric_limits<unsigned long>::min)() << endl;
    	//float
    	cout << "float: 		" << "所占字节数:" << sizeof(float);
    	cout << "	最大值:" << (numeric_limits<float>::max)();
    	cout << "	最小值:" << (numeric_limits<float>::min)() << endl;
    	//size_t
    	cout << "size_t: 	" << "所占字节数:" << sizeof(size_t);
    	cout << "	最大值:" << (numeric_limits<size_t>::max)();
    	cout << "	最小值:" << (numeric_limits<size_t>::min)() << endl;
    	//double
    	cout << "double: 	" << "所占字节数:" << sizeof(double);
    	cout << "	最大值:" << (numeric_limits<double>::max)();
    	cout << "	最小值:" << (numeric_limits<double>::min)() << endl;
    	//long long
    	cout << "long long: 	" << "所占字节数:" << sizeof(long long);
    	cout << "	最大值:" << (numeric_limits<long long>::max)();
    	cout << "	最小值:" << (numeric_limits<long long>::min)() << endl;
    	//long double
    	cout << "long double: 	" << "所占字节数:" << sizeof(long double);
    	cout << "	最大值:" << (numeric_limits<long double>::max)();
    	cout << "	最小值:" << (numeric_limits<long double>::min)() << endl;
    	return 0;
    }
  • 相关阅读:
    ye间模式
    Xutilt网络获取数据
    JUnit
    IntelliJ IDEA快捷键
    Map存放不同数据或对象
    SQL改
    外键约束
    Hibernate之SQL语言查询
    Hibernate之Criteria语言查询
    Hibernate之HQL语言查询
  • 原文地址:https://www.cnblogs.com/hdk1993/p/4371704.html
Copyright © 2020-2023  润新知