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 header file for setw?
Is c++ an oop?
Write is a binary search tree? Write an algo and tell complexity?
What operator is used to access a struct through a pointer a) >> b) -> c) *
Can circle be called an ellipse?
To which numbering system can the binary number 1101100100111100 be easily converted to?
What is the difference between public, private, and protected access?
What is singleton pattern in c++?
declare an array of structure where the members of the structure are integer variable float variable integer array char variable access all elements of the structure using dot operator and this pointer operator
Explain virtual destructor?
How do you instruct your compiler to print the contents of the intermediate file showing the effects of the preprocessor?
What is an accessor in c++?
Write about the various sections of the executable image?
What do you understand by zombie objects in c++?
What is buffering in c++?