码迷,mamicode.com
首页 > 编程语言 > 详细

c++中sizeof的用法

时间:2016-09-21 21:38:21      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

 1 /*测试sizeof()  测试环境:windows 7  64位操作系统    VS2012编译器 */
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int main()
 6 {
 7     char a;
 8     short int b;
 9     int c;
10     long int d;
11     float e;
12     double f;
13     long double g;
14     int* h;
15     double* i;
16     float* j;
17     string strArr1;
18 
19     cout << "sizeof(char) = " << sizeof(a) << endl;
20     cout << "sizeof(short int) = " << sizeof(b) << endl;
21     cout << "sizeof(int) = " << sizeof(c) << endl;
22     cout << "sizeof(long int) = " << sizeof(d) << endl;
23     cout << "sizeof(float) = " << sizeof(e) << endl;
24     cout << "sizeof(double) = " << sizeof(f) << endl;
25     cout << "sizeof(long double) = " << sizeof(g) << endl;
26     cout << "sizeof(int*) = " << sizeof(h) << endl;
27     cout << "sizeof(double*) = " << sizeof(i) << endl;
28     cout << "sizeof(float*) = " << sizeof(j) << endl;
29     cout << "sizeof(string) = " << sizeof(strArr1) << endl;
30    
31     system("pause");
32 
33     return 0;
34 }

 

测试结果:

技术分享

c++中sizeof的用法

标签:

原文地址:http://www.cnblogs.com/dangeal/p/5893997.html

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