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
How do you differentiate between overloading the prefix and postfix increments?
what are function pointers?
What is a v-table?
What is size of string in c++?
How many characters are recognized by ANSI C++?
Implement stack operations with pointers with appropriate exception checks.
What is the best way to take screenshots of a window with c++ in windows?
Write about c++ storage classes?
What is a storage class? Mention the storage classes in c++.
Explain the scope of resolution operator.
How do you import payscale data from non SAP to SAP?is it through LSMW or any other way is there?
Write about all the implicit member functions of a class?
What are the data types in c++?
Define a constructor?
Is multimap sorted c++?