For example, there is a structure
struct A { char a; int i; };
In this case, we have [1 byte] + pad [3 bytes] + int [4 bytes] = 8.
Now let's make a small update in the structure above,
struct A { int i; char a; };
In this case, char comes after int and there is no need to add padding bytes, this means sizeof (A) = 5 bytes, but in this case I also get an 8-byte result. Why?
Ok and what about this case
struct s { int b; double c; char a; };
According to the logic below, there is: size = b[4 bytes] + padding[4 bytes] + c[8] + a[1] + padding[7 bytes to align with double] = 24 , but after execution I get 16 How is this possible?
user1886376
source share