Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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;
};

Answers were Sorted based on User's Feedback



whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

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

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

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

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / shrinidhi

20 bytes.
static is given memory in heap.
for 1st two data members c1 and c2 compiler will take 4
bytes cz of padding.

Is This Answer Correct ?    2 Yes 1 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / sxx010100

20 bytes is right, but static is in data segment portion od
memory, not the heap.

Is This Answer Correct ?    3 Yes 2 No

whats the size of class EXP on 32 bit processor? class EXP { char c1; char c2; int ..

Answer / sandeep mannarakkal

Static is independent of object but associated with class, i.e size of the object is independent of the static.
so here answer is 16 byes.(with the assumption of structure padding is available.)

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

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

0 Answers  


What do the keywords volatile and mean mutable?

0 Answers  


Explain stack & heap objects?

0 Answers  


"How will you merge these two arrays? Write the program Array: A 1 18 22 43 Array: B 3 4 6 20 34 46 55 Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

9 Answers   College School Exams Tests, HCL,


Why we use #include conio h in c++?

0 Answers  


What data encapsulation is in c++?

0 Answers  


What are static and dynamic type checking?

0 Answers  


What are the storage qualifiers?

0 Answers  


What is the iunknown interface?

0 Answers  


Profiler in projects?

2 Answers   Symphony,


How do I open binary files?

1 Answers  


What is Memory Alignment?

2 Answers   TCS,


Categories