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 / ricardo

The answer is 16 (on most compilers), but not for the
reasons stated above.

If the class contained only c1 and c2, the size would be
2. Since i1 is an integer, though, it needs to be aligned
on a 4-byte multiple. The pointer and the other integer
also uses up 4 bytes. So, the total size is 16.

If there were another character field "c3" adjacent to c2,
the size would still be 16 bytes.

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is endl c++?

608


What is function overloading in C++?

737


Why main function is special in c++?

671


What is atoi?

546


Are strings mutable in c++?

694






Write bites in Turbo c++ Header ("Include") Files.

690


What is abstraction with real time example?

623


Why pointer is used in c++?

618


Explain how functions are classified in C++ ?

811


Explain what is class definition in c++ ?

599


What is a down cast?

613


How would you find out if a linked-list is a cycle or not?

555


Why do we use templates?

606


Explain the concept of friend function in c++?

608


What should main() return in c and c++?

529