c++ struct size
Posted
by
kiokko89
on Stack Overflow
See other posts from Stack Overflow
or by kiokko89
Published on 2011-01-09T16:48:06Z
Indexed on
2011/01/09
16:53 UTC
Read the original article
Hit count: 231
struct CExample
{
int a;
}
int main(int argc, char* argv[])
{
CExample ce;
CExample ce2;
cout << "Size:" << sizeof(ce)<< " Address: "<< &ce<< endl;
cout << "Size:" << sizeof(ce2)<< " Address: "<< &ce2 << endl;
CExample ceArr[2];
cout << "Size:" << sizeof(ceArr[0])<< " Address: "<<&ceArr[0]<<endl;
cout << "Size:" << sizeof(ceArr[1])<< " Address: "<<&ceArr[1]<<endl;
return 0;
}
Excuse me I'm just a beginner but i'd like to know why with this code, there is a difference of 12 bytes between the addresses of the first two objects(ce and ce2) (i thought about data allignment), but there is only a difference of 4 bytes between the two objects in the array. Sorry for my bad English...
© Stack Overflow or respective owner