Find the size of a union - C Language Programming

Program in C Language to

Click here to open this program in Turbo C++

 Statement - Find the size of a union
 Programmer - Vineet Choudhary
 Written For -

#include <stdio.h>
#include <conio.h>

void main()
    union sample
        int   m;
        float n;
        char  ch;
    union sample u;
    printf("The size of union =%d\n", sizeof(u));
    /*initialization */
    u.m = 25;
    printf("%d %f %c\n", u.m, u.n,;
    u.n = 0.2;
    printf("%d %f %c\n", u.m, u.n,; = 'p';
    printf("%d %f %c\n", u.m, u.n,;
}    	/*End of main() */

 The size of union =4
 25 12163373596672.000000 
 -13107 0.200000 Õ
 -13200 0.199999 p
You've successfully subscribed to Developer Insider
Great! Next, complete checkout for full access to Developer Insider
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.