Finding the difference in size of addresses(padding)

23 views Asked by At

I have a struct in c such that,

typedef struct {
    char ch;
    int num;
} structB;

Now by how many bytes should the addresses of ch and num differ based on the addresses that they are stored on? When I run sizeof, the size of the structB is 8, but char is supposed to be 1 byte? So, should the elements inside the struct still differ by 4 bytes? I am a bit confused on this.

Note: The question seems to be closed due to it being similar as another one, but I am still confused regarding padding. So could someone explain with reference to the structB provided above?

0

There are 0 answers