c++ struct size
- by kiokko89
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...