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 are the benefits of oop in c++?
What are the two shift operators and what are their functions?
Is c++ pass by reference or value?
How does the copy constructor differ from the assignment operator (=)?
Can we define function inside main in c++?
What is using namespace std in c++?
What is abstraction in c++?
Can we get the value of ios format flags?
What is meant by entry controlled loop? What all C++ loops are exit controlled?
What is encapsulation in C++? Give an example.
What are the two main components of c++?
How do you declare A pointer to function which receives an int pointer and returns a float pointer
List the types of polymorphism in c++?
What is the best free c++ compiler for windows?
daily Routine of father