Answers:
there is something called structure padding or data alignment
Computers read and write to memory in small memory blocks called word sized chunks.
(for a 32bit system the word size is 4byte)
So for CPU's convenience to read and write data in word sized chunks (memory blocks)it arranges the data in multiples of 4byte. This is the reason for structure padding.
in this case
struct A
Computers read and write to memory in small memory blocks called word sized chunks.
(for a 32bit system the word size is 4byte)
So for CPU's convenience to read and write data in word sized chunks (memory blocks)it arranges the data in multiples of 4byte. This is the reason for structure padding.
in this case
struct A
{
int a; // 4 bytes
char c[6]; // 6*1 = 6bytes <<-- here it is padded with 2 blank memory blocks to attain 8 bytes(multiple of 4)
double d; // 8bytes
}; // total =18
Login to add comment