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
Is atoi safe?
What are the implicit member functions of class?
Which bit wise operator is suitable for turning off a particular bit in a number?
What is auto type c++?
Write a program which uses Command Line Arguments
What happens when you make call 'delete this;'?
What are the advantages of using pointers in a program?
Describe friend function & its advantages.
Write a C++ Program to check whether a number is prime number or not?
What is the latest version on c++?
Does c++ have string data type?
Can I learn c++ without knowing c?
what is C++ objects?
What is the difference between while and do while loop? Explain with examples.
What is the full form of dos?