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
What is the error in the code below and how should it be corrected?
What is time h in c++?
What is the difference between prefix and postfix versions of operator++()?
What is heap sort in c++?
Who was the creator of c++?
What is endl c++?
What is functions syntax in c++?
What is the type of this pointer in c++?
What are c++ variables?
How do you master coding?
Can I uninstall microsoft c++ redistributable?
What is the difference between public and private data members?
Will this c++ program execute or not?
Which one between if-else and switch is more efficient?
Which recursive sorting technique always makes recursive calls to sort subarrays that are about half size of the original array?