As per my knowledge, By default 4-byte alignment will be done. say
typedef struct
{
int data7;
unsigned char data8;
//3 -bytes will be added here.
}Sample1;
so sizeof(Sample1)
will be 8.
But for the following structure, why padding is not happened?.
typedef struct
{
unsigned char data1;
unsigned char data2;
unsigned char data3;
unsigned char data4;
unsigned char data5;
unsigned char data6;
}Sample2;
But the sizeof(Sample2) is 6 only. This Sample2 is not a 4 byte aligned structure?
EDIT::
As per Wiki
Data alignment means putting the data at a memory offset equal to some multiple of the word size, which increases the system's performance due to the way the CPU handles memory.
But members of Sample2 will not be aligned in multiples of two right??
Thanks.