Using Unions - C Programming
C Program to create user‒defined datatype from structure.
/* C Program to create user‒defined datatye */
#include<stdio.h>
#include<conio.h>
void main()
{
/* Local definitions */
typedef struct
{
char name[20];
char gender[2];
int age;
}rec;
rec candidate[2];
int a;
/* Statement */
clrscr();
for(a=0;a<2;a++)
{
printf("Name of the Employee: ");
scanf("%s", candidate[a].name);
printf("Gender: ");
scanf("%s", candidate[a].gender);
printf("Age: ");
scanf("%d", &candidate[a].age);
}
printf("\nName\t Gender\t Age\n");
for(a=0;a<2;a++)
{
printf("%s\t", candidate[a].name);
printf("%s\t", candidate[a].gender);
printf("%d\n", candidate[a].age);
}
getch();
} /* main */
OUTPUT
Name of the Employee: Mahi
Gender: m
Age: 20
Name of the Employee: Suma
Gender: f
Age: 25
Name Gender Age
Mahi m 20
Suma f 25
EXPLANATION: In the above program, user‒defined data type rec is created using typedef statement. The rec datatype consists of two character and one integer field. An array candidate[2] is declared based on rec datatype. The first for loop and scanf() statement reads data. The second for loop and printf() statement prints the content of array element.
Computer Programming C Laboratory: Unions C Programs : Tag: C Programming : - C Program to create user-defined datatype from structure
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation