不同的系统中,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为字节的位数。

下图为程序的运行结果:

C++ 整型长度的获取 不同的系统的更多相关文章

  1. GO语言学习——基本数据类型——整型、浮点型、复数、布尔值、fmt占位符

    基本数据类型 整型 整型分为以下两个大类: 按长度分为:int8.int16.int32.int64 对应的无符号整型:uint8.uint16.uint32.uint64 其中,uint8就是我们熟 ...

  2. Python基础:数值(布尔型、整型、长整型、浮点型、复数)

    一.概述 Python中的 数值类型(Numeric Types)共有5种:布尔型(bool).整型(int).长整型(long).浮点型(float)和复数(complex). 数值类型支持的主要操 ...

  3. python基础-基本数据类型总结_整型(int)_字符型(str)_day3

     一.基本数据类型 1.整型(int) ps1:数字 int ,所有的功能,都放在int里a1 = 123a1 = 456 ps2: int 将字符串转换为数字 # -int # 将字符串转换为数字 ...

  4. Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习

    #coding=utf-8 __author__ = 'Administrator' #Python变量类型 #Python数字,python支持四种不同的数据类型 int整型 long长整型 flo ...

  5. Go语言类型(布尔、整型、数组、切片、map等)

    1.基本类型 布尔类型:bool 注意:布尔类型不能接受其他类型的赋值,不支持自动或强制的类型转换. 整型:int8.byte(uint8).int16.int.uint.uintptr int.ui ...

  6. python02 运算符,基本数据类型,整型,字符串

    1.python开发IDE pycharm,python编写工具,, #专业版 #不需要汉化 注册码问题解决 https://www.cnblogs.com/evlon/p/4934705.html整 ...

  7. CVE-2018-14634 - Linux create_elf_tables()中的整型溢出 - 翻译

    原文:https://seclists.org/oss-sec/2018/q3/274 摘要 Qualys研究实验室的安全团队发现一个位于Linux内核函数create_elf_tables()中的整 ...

  8. python --- 03 整型 bool 字符串 for循环

    一.整型(int) 基本操作: 1.+ - * / % // ** 2.  .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 二.布尔值(bool) True  False 1. ...

  9. python之路---03 整型 bool 字符串 for循环

    十三.整型(int) 基本操作: 1.+ - * / % // ** 2.  .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 十四.布尔值(bool) True  False ...

随机推荐

  1. Android 极光推送JPush---自定义提示音

    极光推送提供三种方法实现Notification通知 三方开发平台发送普通消息,客户端设置PushNotificationBuilder,实现基础的Notification通知 三方开放平台发送普通消 ...

  2. iptable防范ddos攻击

    Basic DoS Protection https://github.com/MPOS/php-mpos/wiki/Basic-DoS-Protection # Rule 1: Limit New ...

  3. HttpWebRequest Post请求webapi

    1.WebApi设置成Post请求在方法名加特性[HttpPost]或者方法名以Post开头如下截图: 2.使用(服务端要与客户端对应起来)[单一字符串方式]:注意:ContentType = &qu ...

  4. JAX-WS @WebParam自定义参数名称无效

    在使用myeclipse 自动对service方法类进行创建webservice服务时,默认创建参数命名都是arg0-9 这样就导致生成的xml配置文件命名不规范,需要对参数名称进行修改: myecl ...

  5. May 05th 2017 Week 18th Friday

    No matter what have happened today, the sun will just rise in the morning of tomorrow. 无论今天发生了什么,明天早 ...

  6. MHA 日常维护命令集

    MHA 日常维护命令集 1.查看ssh登陆是否成功 masterha_check_ssh --global_conf=/etc/masterha/masterha_default.conf --con ...

  7. C# 驱动的mongodb的分页查询简单示例

    /// <summary> /// mongodb分页查询 /// </summary> /// <typeparam name="T">< ...

  8. 【BZOJ1269】[AHOI2006] 文本编辑器editor(Splay)

    点此看题面 大致题意: 让你维护一个字符串,有插入字符串.删除区间.反转区间和输出单个字符操作. \(Splay\) 这应该是一道比较简单的\(Splay\)题(虽然因为各种细节我调了很久). 我们可 ...

  9. 2017.11.22 mysql数据库实现关联表更新sql语句

    比如有两张表,其中一张表某个字段的值要关联另一张表进行统计,就要用到mysql的update方法,并且left join另一张表进行联合查询. mysql关联表更新统计 sql语句如下: 代码如下 复 ...

  10. python_1_变量的使用

    print("hello word") name="Qi Zhiguang" print("My name is",name) name2= ...