c - Output of following code with integer, float, char variable -


this question has answer here:

when run following, gives me output 20. int of 4 byte,float of 4 byte , character array of 10 byte, total 18 byte. why getting output 20 byte?

#include<stdio.h>  struct emp {     int id;     char name[10];     float f; }e1; main() {     printf("\n\tsize of structure is==>%d\n",sizeof(e1)); } 

it address alignment.

see :

int 4

char 10 ==> 12 alignment

float 4

like :

iiii cccc cccc cc^^  <-- data pading make address alignment. ffff 

total 20


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -