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...


whats the size of class EXP on 32 bit processor?
class EXP
{
char c1;
char c2;
int i1;
int i2;
char *ptr;
static int mem;
};

Answers were Sorted based on User's Feedback



whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / jaroosh

Both answers are wrong.
First of all, static - class data do NOT contribute to the
class'/objects overall size.
Second, its totally wrong to assume that c1 and c2 will be
given both padding of 3 bytes (so they end up taking space
of 4). Why ?
Because (though Im not sure about every compiler, but 99% of
them will do something like the following) it is simply a
waste of space.
Here are the sizes of member variables of EXP :
class EXP
{
char c1; //1 byte
char c2; //1 byte + 2 bytes of padding! = 3 bytes
int i1; //4 bytes
int i2; //4 bytes
char *ptr; //4 bytes (compiler specific)
static int mem; // 0 bytes
};
this is why on most compilers
sizeof(EXP) is 16.

Is This Answer Correct ?    7 Yes 0 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / ricardo

The answer is 16 (on most compilers), but not for the
reasons stated above.

If the class contained only c1 and c2, the size would be
2. Since i1 is an integer, though, it needs to be aligned
on a 4-byte multiple. The pointer and the other integer
also uses up 4 bytes. So, the total size is 16.

If there were another character field "c3" adjacent to c2,
the size would still be 16 bytes.

Is This Answer Correct ?    4 Yes 0 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / shrinidhi

20 bytes.
static is given memory in heap.
for 1st two data members c1 and c2 compiler will take 4
bytes cz of padding.

Is This Answer Correct ?    2 Yes 1 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / sxx010100

20 bytes is right, but static is in data segment portion od
memory, not the heap.

Is This Answer Correct ?    3 Yes 2 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / sandeep mannarakkal

Static is independent of object but associated with class, i.e size of the object is independent of the static.
so here answer is 16 byes.(with the assumption of structure padding is available.)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is an ABC: an "Abstract Base Class"?

1 Answers  


What is auto used for in c++?

0 Answers  


What does it mean to declare a member function as virtual?

0 Answers  


What is a far pointer? where we use it?

0 Answers  


Which software is best for coding?

0 Answers  


How do I run a program in notepad ++?

0 Answers  


How to tokenize a string in c++?

0 Answers  


differance between copy & clon

1 Answers   Microsoft,


What are the restrictions apply to constructors and destructors?

0 Answers  


Why is c++ still used?

0 Answers  


write a program to add two numbers without using an arithmetic operator.

1 Answers   NIIT,


What is static class data?

0 Answers  


Categories