您的位置:首页 > 编程语言 > C语言/C++

C++ 查看类的内存大小

2016-04-04 15:49 621 查看
#include <iostream>

using namespace std;

class Demo
{
private:
int x;
double y;
};

int main()
{
cout << sizeof(Demo) << endl;
cout << sizeof(char) << endl;
cout << sizeof(int) << endl;
cout << sizeof(double) << endl;

cout << sizeof(Demo*) << endl;
cout << sizeof(char*) << endl;
cout << sizeof(int*) << endl;
cout << sizeof(double*) << endl;
return 0;
}


使用sizeof() 函数。

如果类Demo中的double为指针的话,则类Demo的大小为8 。为double类型的话,则类Demo的大小为16,不知道原因。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: