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,不知道原因。
相关文章推荐
- C++之于C
- C++抽象类
- C++抽象类
- C++ 析构函数
- hihocoder: 1239 Fibonacci(微软2016校园招聘9月在线笔试)
- c++中string、const char*和char*之间的相互转换
- C语言小知识
- C++ 中临时对象 和 const 对象 的一个区别
- C++中4种强制类型转化。static_cast,const_cast,reinterpret_cast,dynamic_cast
- C/C++—— C++中函数重写和函数重载
- C语言所写的简单的贪吃蛇代码
- 猜数字(c语言实现)
- C++ 类型转换构造函数
- C++中的类模板详细讲述
- [转载]C++中类的组合
- C/C++—— C++中定义虚析构函数的原因
- C语言一些关于位操作符的小练习
- C++ 构造函数
- C/C++—— C++中构造函数不能是虚函数的原因分析
- C++ error: default argument given for parameter 1