Example : A C program to store values in union and display them.
#include<stdio.h>
#include<string.h>
#include<conio.h>
union student
{
char sname[20];
char subject[20];
float percentage;
};
void main()
{
union student stu;
strcpy(stu.sname,"Suman");
strcpy(stu.subject,"Computer");
stu.percentage = 34.10;
printf("Values of Union of students are :\n");
printf(" \nStudent Name is : %s ", stu.sname);
printf(" \nSubject is : %s ", stu.subject);
printf(" \n\nPercentage marks is: %f ", stu.percentage);
getch();
}
0 Comments