码迷,mamicode.com
首页 > 其他好文 > 详细

003--sizeof的使用

时间:2015-10-24 17:14:55      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

sizeof用于获取类型或变量的内存大小。可对类型名或变量使用sizeof。对类型(如int)使用sizeof运算符时,应该将名称放在括号中;但对变量名(n_short)使用该运算符,括号是可选的:

技术分享
 1 #include <iostream>
 2 #include <climits>
 3 
 4 int main(){
 5     using namespace std;
 6     int n_int=INT_MAX;
 7     short n_short=SHRT_MAX;
 8     long n_long=LONG_MAX;
 9     long long n_llong=LLONG_MAX;
10 
11     cout<<"int is "<<sizeof(int)<<" bytes."<<endl;
12     cout<<"short is "<<sizeof n_short<<" bytes."<<endl;
13     cout<<"long is "<<sizeof n_long<<" bytes."<<endl;
14     cout<<"long long is "<<sizeof n_llong<<" bytes."<<endl;
15     cout<<endl;
16 
17     cout<<"Maximum values:"<<endl;
18     cout<<"int: "<<n_int<<endl;
19     cout<<"short: "<<n_short<<endl;
20     cout<<"long: "<<n_long<<endl;
21     cout<<"long long: "<<n_llong<<endl;
22 
23     cout<<"Minimum int value:"<<INT_MIN<<endl;
24     cout<<"Bits per byte: "<<CHAR_BIT<<endl;
25 
26     return 0;
27 }
View Code

 

003--sizeof的使用

标签:

原文地址:http://www.cnblogs.com/gis-user/p/4907110.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!