mardi 29 novembre 2016

size of a class object

I have wrritten the following class

class ClientData1
 {
 public:
int accountNumber;

 double balance;
 char lastName[15];
 char firstName[14];
 };
int main()
{
    ClientData1 c;  
cout<<"sizeof( ClientData )"<<sizeof( ClientData1 )<<endl;
cout<<"sizeof( accountNumber  )  =="<<sizeof( c.accountNumber )<<endl;;
cout<<"sizeof( lastName )  =="<<sizeof( c.lastName )<<endl;
cout<<"sizeof( firstName )  =="<<sizeof( c.firstName )<<endl;
cout<<"sizeof( balance )  =="<<sizeof(c.balance )<<endl;

    return 0;
}

the output is 
sizeof( ClientData )=48
sizeof( accountNumber)=4
sizeof( lastName ) =15
sizeof( firstName ) = 14  
sizeof( balance )= 8

But according the fact that size of a class object is the sum of the sizes of all of its data members, size of clientdata should be 41.. why size is 48...plz help

Aucun commentaire:

Enregistrer un commentaire