struct s1
{
int a;
char b;
};
struct s2
{
char b;
};
struct s3
{
char a[3];
};
int main()
{
s1 obj1;
s2 obj2;
s3 obj3;
cout<<sizeof(obj1)<<endl; // prints 8
cout<<sizeof(obj2)<<endl; // prints 1
cout<<sizeof(obj3)<<endl; // prints 3
return 0;
}
I have read the concept of structure padding, packing, and alignment of memory rules etc.... but I didn't understand the reason why there is no padding in case of struct s2 and s3 ?
EDIT: I am working on 32 bit-machine(word size is 4 bytes)