美文网首页
[5]-变量-整型

[5]-变量-整型

作者: vikin_ | 来源:发表于2016-09-29 22:12 被阅读11次

因为操作系统不同,所以变量类型的大小也不相同;


//引入头文件
#include <climits>  //老版本为 limits.h

1、获取类型的最大值

cout << INT_MAX << endl;
//or
cout << SHRT_MAX << endl;
//or
cout << LONG_MAX << endl;
//or
cout << LLONG_MAX << endl;

2、获取变量的大小

//使用预定义的sizeof函数,单位:bytes
int i_int = INT_MAX;
sizeof(i_int);  
//or
sizeof i_int;

3、获取类型的最小值

cout << INT_MIN << endl;
.......

4、获取每个字节大小

cout << CHAR_BIT << endl;

相关文章

网友评论

      本文标题:[5]-变量-整型

      本文链接:https://www.haomeiwen.com/subject/wrdlyttx.html