c++中sizeof的用法

时间:2021-05-18 04:35:38
 /*测试sizeof()  测试环境:windows 7  64位操作系统    VS2012编译器 */
#include <iostream>
using namespace std; int main()
{
char a;
short int b;
int c;
long int d;
float e;
double f;
long double g;
int* h;
double* i;
float* j;
string strArr1; cout << "sizeof(char) = " << sizeof(a) << endl;
cout << "sizeof(short int) = " << sizeof(b) << endl;
cout << "sizeof(int) = " << sizeof(c) << endl;
cout << "sizeof(long int) = " << sizeof(d) << endl;
cout << "sizeof(float) = " << sizeof(e) << endl;
cout << "sizeof(double) = " << sizeof(f) << endl;
cout << "sizeof(long double) = " << sizeof(g) << endl;
cout << "sizeof(int*) = " << sizeof(h) << endl;
cout << "sizeof(double*) = " << sizeof(i) << endl;
cout << "sizeof(float*) = " << sizeof(j) << endl;
cout << "sizeof(string) = " << sizeof(strArr1) << endl; system("pause"); return ;
}

测试结果:

c++中sizeof的用法