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;
};

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you differentiate between overloading the prefix and postfix increments?

595


what are function pointers?

582


What is a v-table?

650


What is size of string in c++?

558


How many characters are recognized by ANSI C++?

901






Implement stack operations with pointers with appropriate exception checks.

569


What is the best way to take screenshots of a window with c++ in windows?

573


Write about c++ storage classes?

757


What is a storage class? Mention the storage classes in c++.

595


Explain the scope of resolution operator.

633


How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?

3205


Write about all the implicit member functions of a class?

602


What are the data types in c++?

523


Define a constructor?

594


Is multimap sorted c++?

559