首页 > 其他 > 详细

003--sizeof的使用

时间:2015-10-24 17:12:24      阅读:268      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!