c++中sizeof的用法


 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 }

 

測試結果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM