#include <iostream>
using namespace std;
class A
{
public:
int val;
char c1;
};
class B: public A
{
public:
char c2;
};
class C: public B
{
public:
char c3;
};
int main()
{
cout << sizeof(A) << ", " << sizeof(B) << ", " << sizeof(C) << endl;
return 0;
}
The output is 8, 12, 12. The size of B is 12 because there are 3 bytes padding after A::c1. But why the size of C is 12 too? Aren't there bytes padding after B::c2? (The compiler I used is gcc 4.8)