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 / venkat

How the conpiler know what data type is nexe to the current
data type?
So when checking the current data type to allocate memory,
previous data type is considered for padding.

In general int should start on 4byte address i.e. end 2
bits should be 00 Ex: 0x2000,2004,2008,200C etc..

Like that double has to start or to be save d at an address
which has last 3 bits a 000. Ex: 0x2000,2008,2010,2018 etc.

Similarly short on 2 byte boundary.. i.e last bit should 0.

Now when compiler see a double, checks what's the previous
one and if it's Char adds 7 bytes pad, if it's short-adds
6bytes padd and if it's int adds 4bytes pad.

Finally, in some compilers the total structure length is
padded to 2 to the power. Ex: If total size of all elements
in a structure are 28, compiler gives 32bytes i.e 2 to the
power of 5 ehich greater than the requirement.

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are register variables?

1072


What function initalizes variables in a class: a) Destructor b) Constitutor c) Constructor

1102


What do the header files usually contains?

1000


In which header file does one find isalpha() a) conio.h b) stdio.h c) ctype.h

1158


What does I ++ mean in c++?

1035


What is oops in c++?

996


Are c and c++ similar?

997


Which is better c++ or java?

928


Do you know what is overriding?

1103


What are built-in functions? What is the syntax for the definition?

1027


What is class syntax c++?

1092


Write a Program for read a line from file from location N1 to N2 using command line arguments. Eg:exe 10 20 a.c

1230


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

1037


Write a program that takes a 5 digit number and calculates 2 power that number and prints it.

2527


What are dynamic type checking?

983