Explain Pointer to Union in C Programming With Example -99webcode
#include<stdio.h>
union student
{
int a;
char b;
float marks;
};
void main()
{
union student s1;
union student *ptr=&s1;
s1.a=10;
s1.b='d';
s1.marks=88.25;
printf("%d\n",ptr->a); // also write as printf("%d",(*ptr).a);
printf("%c\n",ptr->b); //also write as printf("%c",(*ptr).b);
printf("%f\n",ptr->marks);//also write as printf("%f",(*ptr).marks);
printf("%d",sizeof(s1));
}
output :
1118863360
1118863360
88.250000
4