My two questions regarding structures and union are:
1. Why does the following program results in segmentation fault.
2. Why the output of the code 24.Code:#include<stdio.h> #include<conio.h> int main(void) { union a { char ch[2]; int i; }; union a key; key.ch[0]='5'; printf("%d %d %d",key.ch[0],key.ch[1],key.i); getch(); }
I know slack byte thing but that should also result in 20bytes coz my PC's word size is 4 bytes(32bit OS).Code:#include<stdio.h> #include<conio.h> int main(void) { struct { char ch;// char 1 byte int i;//int 4 bytes float f;//float 4 bytes double r;// double 8 bytes }v; printf("%d",sizeof(v)); getch(); }
Thanks



LinkBack URL
About LinkBacks



