Unions are a concept of structures and therefore follow the same syntax as structures.however,there is major distinction between them in terms of storage.in structures,each member has its own storage location,whereas all the members of a union use the same location.
a union can be declared using the keyword union as follow the syntax of union.
union tag_name
{
member;
}union variables;
#include <stdio.h>
union student
{
char name[32];
}u;
void main()
{
printf("Enter Student Name:\n");
scanf("%s",&u.name);
printf("Student Name: %s",u.name);
getch();
}
Output
Enter Student Name:Johan
Student Name: Johan