#include <iostream> #include <ostream> class base {}; class derived : public base {}; int main() { using namespace std; cout << sizeof(base) << '\n'; cout << sizeof(derived) << '\n'; base b[3]; cout << sizeof(b) << '\n'; derived d[5]; cout << sizeof(d) << '\n'; }
1 1 3 5
3.6.sizeof | ||||
3.6.1. | Demonstrate sizeof. | |||
3.6.2. | sizeof a union | |||
3.6.3. | sizeof a class | |||
3.6.4. | Object sizes | |||
3.6.5. | Using the sizeof operator for base class and derived class | |||
3.6.6. | Use sizeof operator on an array name: returns the number of bytes in the array |