不同的系统中,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 libs库中的armeabi-v7a,armeabi和x86

    以下内容转载于:http://blog.csdn.net/liumou111/article/details/52949156 1.区别: 这三者都表示的是CPU类型,早期的Android系统几乎只支 ...

  2. 翻译-ExcelDNA开发文档-首页

    转载自个人主页 前言 ExcelDNA是一名国际友人开发的开源框架,文档全是英文文档,当时看的时候非常吃力,现在将英文文档翻译过来,为的是让自己加深印象以及自己以后看的时候能不用这么吃力. 介绍 Ex ...

  3. DEEP LEARNING 大满贯课程表

    Reinforcement Learning post by ISH GIRWAN Courses/Tutorials Deep Reinforcement Learning, Spring 2017 ...

  4. April 25 2017 Week 17 Tuesday

    Have you ever known the theory of chocie? There are a bunch of axiems, but there are only two thing ...

  5. 深入了解MongoDB

    一.介绍: 数据库分为关系型数据库和非关系型数据库 关系型数据库是建立在关系模型上的数据库,主要的有Oracle MySQL Microsoft SQL Server NoSQL是非关系型数据存储的广 ...

  6. c++中explicit关键字用法

    C++ explicit关键字用来修饰类的构造函数,表明该构造函数是显式的,既然有"显式"那么必然就有"隐式",那么什么是显示而什么又是隐式的呢? 如果c++类 ...

  7. java文件

    File类 为了很方便的代表文件的概念,以及存储一些对于文件的基本操作,在java.io包中设计了一个专门的类——File类. 在File类中包含了大部分和文件操作的功能方法,该类的对象可以代表一个具 ...

  8. 【转载】#437 - Access Interface Members through an Interface Variable

    Onece a class implementation a particular interface, you can interact with the members of the interf ...

  9. (转载)Fiddler模拟post四种请求数据

    https://www.cnblogs.com/xiaoxi-3-/p/7612254.html https://blog.csdn.net/qq_15283475/article/details/5 ...

  10. 如何不安装SQLite让程序可以正常使用

    System.Data.SQLite.dll和System.Data.SQLite.Linq.dll不必在GAC里面,关键在于Machine.config的DBProviderFactories没有正 ...