How to Use typedef for a Union in C? Last Updated : 19 Feb, 2024 Comments Improve Suggest changes Like Article Like Report In C, typedef is used to give an existing type an alias or a new name. In this article, we will learn how to create a typedef for a union in C. Use the typedef union in CWe can define a union and create an alias for it using the typedef keyword which we will be able to use in place of that union name. SyntaxFor defining the union and creating a typedef simultaneously use: typedef union UnionName { // Member declaration} TypedefName;For defining the union first, then creating a typedef use: union UnionName { // Member declaration};typedef union UnionName TypedefName;C Program to Create an Alias Using typedef for a unionThe below program demonstrates the use typedef keyword to create a typedef for a union in C. C // C program to create typedef for union #include <stdio.h> // Defining a union named MyUnion with three members union MyUnion { int integer; float floating_point; char character; }; // Creating a typedef for the union typedef union MyUnion MyUnion; int main() { MyUnion data; // Declaring a variable of type MyUnion // Assigning printing the values to the member of the // union data.integer = 100; data.floating_point = 5.14; data.character = 'A'; // printing the values to the member of the union printf("Integer value: %d\n", data.integer); printf("Floating-point value: %.2f\n", data.floating_point); printf("Character value: %c\n", data.character); return 0; } OutputInteger value: 1084521025 Floating-point value: 5.14 Character value: A Comment More infoAdvertise with us Next Article How to Use typedef for a Union in C? R rahul709392 Follow Improve Article Tags : C Programs C Language C-Structure & Union C-Data Types C Examples +1 More Similar Reads How to use typedef for a Struct in C? In C, we use typedef to create aliases for already existing types. For structure, we can define a new name that can be used in place of the original struct name. In this article, we will learn how to create a typedef for a structure in C++. Use the typedef struct in CTo create an alias for a structu 2 min read How to Use a Union to Save Memory in C? Unions in C offer a unique mechanism for storing different variables in the same memory location. These variables are called members of the union and can be of different types as well. In this article, we will learn how to use a union to save memory in C. Save Memory using Union in CUnion members sh 2 min read How to Declare a Pointer to a Union in C? Union is a user-defined data type in C language that can contain elements of the different data types and pointers are used to store memory addresses. In this article, we will learn how to declare a pointer to a union in C++. Pointer to Union in CTo declare a pointer to a union first, define a union 2 min read How to Create a Typedef for a Function Pointer in C? In C, a function pointer is a variable that stores the address of a function that can later be called through that function pointer. The typedef is a keyword used to create an alias or alternative name for the existing data types. In this article, we will learn how to create a typedef for a function 2 min read How to Create a Linked List in C? Write a C program to create a linked list.A linked list is a sequential data structure that stores the data in non-contiguous memory locations unlike array. In a linked list, each element is referred to as a node. Each node in the linked list stores data and a pointer to the next node present in the 5 min read How to Declare a Pointer to a Struct in C? Structure (or structs) in the C programming language provides a way to combine variables of several data types under one name and pointers provide a means of storing memory addresses. In this article, we will learn how to declare such a pointer to a struct in C. Declaration of Pointer to Struct in C 2 min read How to Declare a Struct Member Inside a Union in C? A union contains different types of variables as its members and all these members share a memory location. In this article, we will learn how to declare and access the struct member inside a union in C++. Structure Inside Union in CTo declare a structure inside a union we can use the below syntax: 2 min read C Program For Union And Intersection Of Two Linked Lists Write a C program for a given two Linked Lists, create union and intersection lists that contain union and intersection of the elements present in the given lists. The order of elements in output lists doesn't matter.Example: Input:List1: 10->15->4->20List2: 8->4->2->10Output:Inter 10 min read How to avoid Structure Padding in C? Prerequisites: Structure Member Alignment, Padding and Data Packing In Structure, sometimes the size of the structure is more than the size of all structures members because of structure padding. Below is an example of Structure padding: C // C program to show an example // of Structure padding #inc 2 min read How to Modify Struct Members Using a Pointer in C? In C++, we use structure to group multiple different types of variables inside a single type. These different variables are called the members of structures. In this article, we will discuss how to modify the struct member using a pointer in C. Example Input: myStruct.mem1 = 10; myStruct.mem2 = 'a'; 1 min read Like