Linux C++基本数据类型

我就是我 2022-03-16 07:26 422阅读 0赞

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

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

在这里插入图片描述

  1. cout << "数据类型 " << "字节数 " << "最小范围: " << "最大范围: " << endl;
  2. cout << "char " << sizeof (char) << " " << (numeric_limits<char>::min)() << " " << (numeric_limits<char>::max)() << endl;
  3. cout << "int " << sizeof (int) << " " << numeric_limits<int>::min() << " " << numeric_limits<int>::max() << endl;
  4. cout << "short int " << sizeof (short int) << " " << numeric_limits<short int>::min() << " " << numeric_limits<short int>::max() << endl;
  5. cout << "long int " << sizeof (long int) << " " << numeric_limits<long int>::min() << " " << numeric_limits<long int>::max() << endl;
  6. cout << "float " << sizeof (float) << " " << numeric_limits<float>::min() << " " << numeric_limits<float>::max() << endl;
  7. cout << "double " << sizeof (double) << " " << numeric_limits<double>::min() << " " << numeric_limits<double>::max() << endl;
  8. cout << "long double " << sizeof (long double) << " " << numeric_limits<long double>::min() << " " << numeric_limits<long double>::max() << endl;
  9. cout << "bool " << sizeof (bool) << " " << numeric_limits<bool>::min() << " " << numeric_limits<bool>::max() << endl;
  10. cout << "wchar_t " << sizeof (wchar_t) << " " << numeric_limits<wchar_t>::min() << " " << numeric_limits<wchar_t>::max() << endl;
  11. cout << "long " << sizeof (long) << " " << numeric_limits<long>::min() << " " << numeric_limits<long>::max() << endl;
  12. cout << "long long " << sizeof (long long) << " " << numeric_limits<long long>::min() << " " << numeric_limits<long long>::max() << endl;
  13. //无符号数据类型
  14. cout << "unsigned char " << sizeof (unsigned char) << " " << numeric_limits<unsigned char>::min() << " " << numeric_limits<unsigned char>::max() << endl;
  15. cout << "unsigned int " << sizeof (unsigned int) << " " << numeric_limits<unsigned int>::min() << " " << numeric_limits<unsigned int>::max() << endl;
  16. cout << "unsigned long " << sizeof (unsigned long) << " " << numeric_limits<unsigned long>::min() << " " << numeric_limits<unsigned long>::max() << endl;
  17. cout << "unsigned short " << sizeof (unsigned short) << " " << numeric_limits<unsigned short>::min() << " " << numeric_limits<unsigned short>::max() << endl;
  18. cout << "unsigned long long " << sizeof (unsigned long long) << " " << numeric_limits<unsigned long long>::min() << " " << numeric_limits<unsigned long long>::max() << endl;
  19. 数据类型 字节数 最小范围: 最大范围:
  20. char 1 
  21. int 4 -2147483648 2147483647
  22. short int 2 -32768 32767
  23. long int 8 -9223372036854775808 9223372036854775807
  24. float 4 1.17549e-38 3.40282e+38
  25. double 8 2.22507e-308 1.79769e+308
  26. long double 16 3.3621e-4932 1.18973e+4932
  27. bool 1 0 1
  28. wchar_t 4 -2147483648 2147483647
  29. long 8 -9223372036854775808 9223372036854775807
  30. long long 8 -9223372036854775808 9223372036854775807
  31. unsigned char 1
  32. unsigned int 4 0 4294967295
  33. unsigned long 8 0 18446744073709551615
  34. unsigned short 2 0 65535
  35. unsigned long long 8 0 18446744073709551615

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

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

  1. signed
  2. unsigned
  3. short
  4. long

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

发表评论

表情:
评论列表 (有 0 条评论,422人围观)

还没有评论,来说两句吧...

相关阅读

    相关 C51基本数据类型

    C51基本数据类型 C51中基本数据类型主要是指变量类型。变量是指其值可以改变的量。一个变量实质上是代表了内存中的某个存储单元。程序中的变量a,就是指用a命名的某个存储单

    相关 Linux C++基本数据类型

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