C++ 整型长度的获取 不同的系统
不同的系统中,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++ 整型长度的获取 不同的系统的更多相关文章
- GO语言学习——基本数据类型——整型、浮点型、复数、布尔值、fmt占位符
基本数据类型 整型 整型分为以下两个大类: 按长度分为:int8.int16.int32.int64 对应的无符号整型:uint8.uint16.uint32.uint64 其中,uint8就是我们熟 ...
- Python基础:数值(布尔型、整型、长整型、浮点型、复数)
一.概述 Python中的 数值类型(Numeric Types)共有5种:布尔型(bool).整型(int).长整型(long).浮点型(float)和复数(complex). 数值类型支持的主要操 ...
- python基础-基本数据类型总结_整型(int)_字符型(str)_day3
一.基本数据类型 1.整型(int) ps1:数字 int ,所有的功能,都放在int里a1 = 123a1 = 456 ps2: int 将字符串转换为数字 # -int # 将字符串转换为数字 ...
- Python变量类型(l整型,长整形,浮点型,复数,列表,元组,字典)学习
#coding=utf-8 __author__ = 'Administrator' #Python变量类型 #Python数字,python支持四种不同的数据类型 int整型 long长整型 flo ...
- Go语言类型(布尔、整型、数组、切片、map等)
1.基本类型 布尔类型:bool 注意:布尔类型不能接受其他类型的赋值,不支持自动或强制的类型转换. 整型:int8.byte(uint8).int16.int.uint.uintptr int.ui ...
- python02 运算符,基本数据类型,整型,字符串
1.python开发IDE pycharm,python编写工具,, #专业版 #不需要汉化 注册码问题解决 https://www.cnblogs.com/evlon/p/4934705.html整 ...
- CVE-2018-14634 - Linux create_elf_tables()中的整型溢出 - 翻译
原文:https://seclists.org/oss-sec/2018/q3/274 摘要 Qualys研究实验室的安全团队发现一个位于Linux内核函数create_elf_tables()中的整 ...
- python --- 03 整型 bool 字符串 for循环
一.整型(int) 基本操作: 1.+ - * / % // ** 2. .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 二.布尔值(bool) True False 1. ...
- python之路---03 整型 bool 字符串 for循环
十三.整型(int) 基本操作: 1.+ - * / % // ** 2. .bit_length() 计算整数在内存中占⽤的⼆进制码的⻓度 如: 十四.布尔值(bool) True False ...
随机推荐
- 从今天开始学习Swift -- Swift 初见 (转)
原文地址:http://www.cocoachina.com/newbie/basic/2014/0604/8675.html Swift系列文章由CocoaChina翻译小组翻译自苹果的官方文档 ...
- (一)Hybrid app混合开发模式
hybrid app是什么? 这里我们先看一下词条上的定义 Hybrid App:Hybrid App is a mobile application that is coded in both br ...
- Native Method
While a 100% pure Java solution is nice in principle, realistically, for an application, there are s ...
- While, DoWhile in WorkFlow.
On 03/03/2010, in 4.0, WF, by bcakiroglu While Activity In a While activity, the activity in the Bod ...
- Android内存监测工具使用
用 Heap监测应用进程使用内存情况的步骤如下:1. 启动eclipse后,切换到DDMS透视图,并确认Devices视图.Heap视图都是打开的:2. 将手机通过USB链接至电脑,链接时需要确认手机 ...
- 在unbuntu 1204(32位)下安装hadoop2.2.0的一些问题
虽然在网上可以找到很多这样的step by step的教程,但是我还是遇到了很多问题.趁着一点记忆,将这些问题记录下来.安装过程参考了以下博客: http://www.cnblogs.com/life ...
- iis 部署网站常见问题
环境IIS6.0,win2003server 首先打开iis,左边菜单选中”Web服务扩展“,讲Active Server Pages 和 ASP.NET v2.0.50727设置为允许 1.创建网站 ...
- django 定制admin
https://www.cnblogs.com/liwenzhou/p/9519321.html
- 如何让MVC和多层架构和谐并存(二)
上一节说了一些笼统的东西,这节说一些实际的操作. 1.取列表.这是一个新闻列表: 对应MVC的model是: public class NewsListModel { /// < ...
- Java集合集锦
1.介绍Collection框架的结构 集合是Java中的一个非常重要的一个知识点,主要分为List.Set.Map.Queue三大数据结构.它们在Java中的结构关系如下: Collection接口 ...