Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

what is the size of this class
class size
{
public:
char data1;
double d;
int data2;
char data3;
double data4;
short data5;
};

please explain the padding for these double variables.

Answer Posted / siva

Hi guys why dont you test properly before posting answers???

the answer is 40. how it is padding is as shown bellow

char data1 1+7 bytes
double d 8 bytes
int data2 4 bytes
char data3 1+7 bytes
double data4 8 bytes
short data5 4 bytes

so 40 bits

padding intermes of char type only, not for int, double and
short.

also, padding depends one next member type.

also observe char member are not in sequence.if they are in
sequence all will use same size as first one.

example:

if above structure is as shown bellow

struct size{
char data1 //1+7 bytes
char data6 //uses above 8 bytes
char data7 //uses above 8 bytes
char data8 //uses above 8 bytes
double d //8 bytes
int data2 //4 bytes
char data3 //1+7 bytes
double data4 //8 bytes
short data5 //4 bytes
}

still its size is 40 byts.

here you guys can observe before char data8 double d is
declared thatsway char data8 is padding to 1+7 = 8 byts
if it is int d then char data8 is padding to 1+3 =4 byts

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Define copy constructor.

1061


What is the difference between #define debug 0 and #undef debug?

1129


How do you print a string on the printer?

990


Which operations are permitted on pointers?

948


Are there interfaces in c++?

941


How should runtime errors be handled in c++?

1087


What is pointer to array in c++?

1084


What is static in c++?

1008


Which operator cannot be overloaded c++?

969


What new()is different from malloc()?

1049


What is the difference between the parameter to a template and the parameter to a function?

1060


Who discovered c++?

984


What is the difference between *p++ and (*p)++ ?

1293


What is the c++ programming language used for?

992


Explain bubble sorting.

1026