How to find the size of a class

Size of a class
which is
class C
{
int i;
char c;
}
int size is 4 and char is 1 but the size of class is coming 8, give the explanation for that?

Questions by sundarkms

Showing Answers 1 - 3 of 3 Answers

This is because, your machine is 32 bit( 4 byte). your structure has two variable, a int and a char. int is 4byte long, so no problem. but char is 1 byte long, and will occupy the other 3 byte for alignment. So the sizeof operator gives the total size 8 byte.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions