0

how does union work?

#include<stdio.h> #include <string.h> int main() { union Data { int i; unsigned char c; }data; data.i=89; data.c='a'; printf( "%d\n", data.i); return 0; } output is 97 (ascaii value of a) why??

7th Aug 2017, 6:40 PM
Rishabh Singh Rajput
Rishabh Singh Rajput - avatar
5 Réponses
0
are you shure? its like.. how?
7th Aug 2017, 7:36 PM
Paul
0
try yourself brother
7th Aug 2017, 7:38 PM
Rishabh Singh Rajput
Rishabh Singh Rajput - avatar
0
i have tried, gave 89 as is in 'i' variable
7th Aug 2017, 7:41 PM
Paul
0
try now brother. one more time
7th Aug 2017, 7:49 PM
Rishabh Singh Rajput
Rishabh Singh Rajput - avatar
0
have you tried compiling it here in the code playground?
9th Aug 2017, 9:01 AM
Paul