As you study the size of the structure and how it fills, let me tell you an interesting thing. The size of the structure depends not only on the members , but also on the order of their announcement . For example, the size of the following structures is different, although both have the same number of members of the same type, the only difference is the order in which they are declared!
struct A
{
int a;
char b;
char c;
};
struct B
{
char b;
int a;
char c;
};
cout << "sizeof(A) = " << sizeof(A) << endl;
cout << "sizeof(B) = " << sizeof(B) << endl;
Conclusion:
sizeof(A) = 8
sizeof(B) = 12
Ideone online demo: http://www.ideone.com/8OoxX
Nawaz source
share