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();
}

 4,517 total views,  1 views today

Categories: C

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.