不同的系统中,C++整型变量中的长度位数是不同的,通常,在老式的IBM PC中,int 的位数为16位(与short相同),而在WINDOWS XP,Win7,vax等很多其他的微型计算机中,为32位(与long 相同)。这点在迁移别人的程序中要注意!!!看别人用的什么系统,自己用的什么系统!

例如,如果获取来自64位win10系统中整型数据的长度,代码如下:

#include<iostream>
using namespace std;
#include<climits>
int main()
{
int n_int = INT_MAX;
short n_short = SHRT_MAX;
long n_long = LONG_MAX;
long long n_llong = LLONG_MAX; cout << "int is " << sizeof (n_int) << " bytes." << endl;
cout << "short is " << sizeof n_short << " bytes."<< endl;
cout << "long is " << sizeof n_long << " bytes." << endl;
cout << "long long is " << sizeof n_llong << " bytes." << endl;
cout << endl; cout << "Maxium values :" << endl;
cout << "int: " << n_int << endl;
cout << "short: " << n_short << endl;
cout << "long: " << n_long << endl;
cout << "long long: " << n_llong << endl; cout << "Minimum values :" << INT_MIN<< endl;
cout << "Bits per byte = " << CHAR_BIT << endl;
cin.get();
return ;
}

其中,头文件包含了关于整型限制的信息,具体的说,他定义了各种限制的符号名称。如INT_MAX表示int 的最大取值,CHAR_BIT为字节的位数。

下图为程序的运行结果:

最新文章

  1. FPGA芯片内部硬件介绍
  2. apache日志轮询技术
  3. 多次drawRect,显示重叠,需要设置背景颜色
  4. C语言初始化——栈的初始化
  5. Mybatis的分页查询
  6. java中synchronized的用法详解
  7. zTree实现访问到第一节点在相同水平当前所选节点数目
  8. 将apache的prefork改成worker
  9. 3.WP8.1开发_为控件增加动画
  10. form表单js提交
  11. ios打包unity应用以及配置签名
  12. systemd取消对服务重启的限制
  13. 如何在Android中的Activity启动第三方应用程序?
  14. 进度条(progress_bar)
  15. awk实例
  16. 浅析vue的双向数据绑定
  17. HDFS的工作流程
  18. django MongoDB上传文件
  19. c++三大概念要分清--重载,隐藏(重定义),覆盖(重写)
  20. Namespace declaration statement has to be the very first statement in the script

热门文章

  1. Java Exception &amp; RTTI
  2. unity工具介绍
  3. 将零散文件使用ICSharpCode.SharpZipLib压缩打包后一次性下载
  4. UIWindow及程序启动的过程
  5. python 不同目录间的模块调用
  6. CloudWAN
  7. COGS 2075. [ZLXOI2015][异次元圣战III]ZLX的陨落
  8. 安装纯净 ubuntu linux (非虚拟机)
  9. (转载)Fiddler模拟post四种请求数据
  10. Nginx启用Gzip压缩js无效的原因