1

Possible Duplicate:
Why isn't sizeof for a struct equal to the sum of sizeof of each member?

Hi all,

i wanted to know how size of below structure comes out to be 24.As per my calculation it should be 20.and one more thing is there any way this structure is taking size of its variable t into account??

Please ignore any syntax error and i am on 32 bit machine

 struct structc
{ 

char        c; 
double      d; 
int         s;
} t;

main()
{
printf("sizeof(structc_t) = %d\n", sizeof(t)); 
} 
Community
  • 1
  • 1
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199

1 Answers1

6

The size of the struct includes padding bytes between is members due to packing alignment, which is compiler- and architecture-dependent (see here for an example)

Update: Not surprisingly, this question is a dupe. For a better answer, see Why isn't sizeof for a struct equal to the sum of sizeof of each member?.

Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806