003--sizeof的使用
2015-10-24 16:34
176 查看
sizeof用于获取类型或变量的内存大小。可对类型名或变量使用sizeof。对类型(如int)使用sizeof运算符时,应该将名称放在括号中;但对变量名(n_short)使用该运算符,括号是可选的:
View Code
#include <iostream> #include <climits> int main(){ using namespace std; 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(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<<"Maximum 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 int value:"<<INT_MIN<<endl; cout<<"Bits per byte: "<<CHAR_BIT<<endl; return 0; }
View Code
相关文章推荐
- 如何让浏览器正确识别网页编码
- Java String.startsWith()
- uva 11752 -The Super Powers (数论)
- 关于数字签名
- 博客同步测试
- uva11029 - Leading and Trailing
- 第一次训练赛的相关总结和教训!
- 刘汝佳训练指南——数论专题知识点总结:
- 程序猿不能错过的十部电影
- 英语“作弊”技巧!
- 一些好的习惯
- android图片压缩
- intel_rapl: no valid rapl domains found in package 0 virtualbox ubuntu
- linux操作系统-脚本入门
- Flume源码-LoggerSink
- 为什么不能在子类的初始化列表里初始化父类的成员
- inline内联函数的优缺点
- 一些oj的返回结果:通过结果找错误,debug。
- 引用 Map 数据结构的排序问题
- vector中find和find_if的用法