Considering an int takes 4 bytes and char takes 1 byte, the size occupied by below structure should be 9 [ 4 + 1 + 4 ], but actually it is 12 bytes [ 4 + 4 + 4 ].
Reason :
char y reserves 4 byte of memory, and y occupy 1 byte and rest 3 allocated bytes are not used.
struct some_struct { int x; char y; int z; }; question 1 : so why does compiler behaves so ? (suppose i have a X8086 architecture)
question 2 : what if it were a union (not struct) ?
Thanks very much all for answers , i realize i should have searched for it on SO only before posting question .
unioncannot be used instead since it does something different than astruct, unless you really want what auniondoes, which is to overlap all the members at the same mememoy location.