struct abc{
char a;
char b;
char c;
};

what is sizeof (struct abc) in gcc ?

it is giving 3, why not 4 bytes.

Recommended Answers

All 3 Replies

Why are you expecting it to be 4 bytes? 3 characters, 1 byte each , total 3 bytes.

He's expecting the compiler it to align all instances of this structure to 4-byte boundaries via padding. I'm not entirely sure if this should actually change the value returned by sizeof().

He's expecting the compiler it to align all instances of this structure to 4-byte boundaries via padding. I'm not entirely sure if this should actually change the value returned by sizeof().

It should.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.