Mega Code Archive

 
Categories / C++ Tutorial / Operators Statements
 

Using the sizeof operator for base class and derived class

#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