#include <iostream>
using namespace std;
class Base
{
int first_int; //size of int is 4 byte
int second_int; //so size of Base class is 8 byte
};
class derived:public Base
{
int derived_member;
int another_derived_member;
int new_member;
};
class home
{
Base base_1;
Base base_2;
};
int main()
{
cout << sizeof(derived) << endl; //the size of derived class is (8+12=20) byte
cout << sizeof(Base) << endl;
cout << sizeof(home) << endl; //the size of home class is (8+8)=16 byte
}
OUTPUT:
20
8
16
using namespace std;
class Base
{
int first_int; //size of int is 4 byte
int second_int; //so size of Base class is 8 byte
};
class derived:public Base
{
int derived_member;
int another_derived_member;
int new_member;
};
class home
{
Base base_1;
Base base_2;
};
int main()
{
cout << sizeof(derived) << endl; //the size of derived class is (8+12=20) byte
cout << sizeof(Base) << endl;
cout << sizeof(home) << endl; //the size of home class is (8+8)=16 byte
}
OUTPUT:
20
8
16
No comments:
Post a Comment