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

Is atoi safe?

828


What are the implicit member functions of class?

831


Which bit wise operator is suitable for turning off a particular bit in a number?

867


What is auto type c++?

867


Write a program which uses Command Line Arguments

865


What happens when you make call 'delete this;'?

821


What are the advantages of using pointers in a program?

904


Describe friend function & its advantages.

938


Write a C++ Program to check whether a number is prime number or not?

867


What is the latest version on c++?

883


Does c++ have string data type?

891


Can I learn c++ without knowing c?

814


what is C++ objects?

918


What is the difference between while and do while loop? Explain with examples.

863


What is the full form of dos?

783