Linux C++基本数据类型

计算机的内存是以字节byte为单位进行组织的。一个字节是我们能够在c++程序中操作的最小内存单位。
下面我们通过程序打印一下c++中常见的数据类型以及其所能够存储的数据范围。

常见的数据类型可参考下面

在这里插入图片描述

 cout << "数据类型   " << "字节数    " << "最小范围:    " << "最大范围:  " << endl;
    cout << "char   " << sizeof (char) << "   " << (numeric_limits<char>::min)() << "  " << (numeric_limits<char>::max)() << endl;
    cout << "int   " << sizeof (int) << "   " << numeric_limits<int>::min() << "  " << numeric_limits<int>::max() << endl;
    cout << "short int   " << sizeof (short int) << "   " << numeric_limits<short int>::min() << "  " << numeric_limits<short int>::max() << endl;
    cout << "long int   " << sizeof (long int) << "   " << numeric_limits<long int>::min() << "  " << numeric_limits<long int>::max() << endl;
    cout << "float   " << sizeof (float) << "   " << numeric_limits<float>::min() << "  " << numeric_limits<float>::max() << endl;
    cout << "double   " << sizeof (double) << "   " << numeric_limits<double>::min() << "  " << numeric_limits<double>::max() << endl;
    cout << "long double   " << sizeof (long double) << "   " << numeric_limits<long double>::min() << "  " << numeric_limits<long double>::max() << endl;
    cout << "bool   " << sizeof (bool) << "   " << numeric_limits<bool>::min() << "  " << numeric_limits<bool>::max() << endl;
    cout << "wchar_t   " << sizeof (wchar_t) << "   " << numeric_limits<wchar_t>::min() << "  " << numeric_limits<wchar_t>::max() << endl;
    cout << "long   " << sizeof (long) << "   " << numeric_limits<long>::min() << "  " << numeric_limits<long>::max() << endl;
    cout << "long long " << sizeof (long long) << "   " << numeric_limits<long long>::min() << "  " << numeric_limits<long long>::max() << endl;
    //无符号数据类型
    cout << "unsigned char   " << sizeof (unsigned char) << "   " << numeric_limits<unsigned char>::min() << "  " << numeric_limits<unsigned char>::max() << endl;
    cout << "unsigned int   " << sizeof (unsigned int) << "   " << numeric_limits<unsigned int>::min() << "  " << numeric_limits<unsigned int>::max() << endl;
    cout << "unsigned long   " << sizeof (unsigned long) << "   " << numeric_limits<unsigned long>::min() << "  " << numeric_limits<unsigned long>::max() << endl;
    cout << "unsigned short   " << sizeof (unsigned short) << "   " << numeric_limits<unsigned short>::min() << "  " << numeric_limits<unsigned short>::max() << endl;
    cout << "unsigned long long   " << sizeof (unsigned long long) << "   " << numeric_limits<unsigned long long>::min() << "  " << numeric_limits<unsigned long long>::max() << endl;
数据类型   字节数    最小范围:    最大范围:  
char   1   �  
int   4   -2147483648  2147483647
short int   2   -32768  32767
long int   8   -9223372036854775808  9223372036854775807
float   4   1.17549e-38  3.40282e+38
double   8   2.22507e-308  1.79769e+308
long double   16   3.3621e-4932  1.18973e+4932
bool   1   0  1
wchar_t   4   -2147483648  2147483647
long   8   -9223372036854775808  9223372036854775807
long long 8   -9223372036854775808  9223372036854775807
unsigned char   1     �
unsigned int   4   0  4294967295
unsigned long   8   0  18446744073709551615
unsigned short   2   0  65535
unsigned long long   8   0  18446744073709551615

上面的结果仅供参考,不同的机器上会有差异存在。

一些基本类型可以使用一个或多个类型修饰符进行修饰:

signed
unsigned
short
long

关于修饰符的更多内容这里就不多说了,不清楚的可以查阅下资料嘚。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值