confusing output


class A{
char a;
class B:public A{
int b;

void main(){

B ob;

cout<<sizeof ob<<endl;

this program shows the output 8 bytes that is confusing actually is should show 5 bytes because char a size is 1 byte and int b size is 4 byte.....please help me to understand this contradiction ....
This should answer your question :

Edit : C structs and C++ classes works similarly in this case.
Last edited on
Topic archived. No new replies allowed.