Unions and Enumerations
📘 C
👁 29 views
📅 Dec 22, 2025
⏱ Estimated reading time: 2 min
A union is a user-defined data type in which all members share the same memory location.
Difference Between Structure and Union
-
Structure allocates separate memory for each member
-
Union allocates memory equal to the largest member only
Declaration of Union
Example of Union
Declaring Union Variables
Accessing Union Members
-
Use dot (
.) operator
Example Program (Union)
Applications of Union
-
Memory-efficient programming
-
Embedded systems
-
Handling multiple data types in same memory
Enumerations in C
An enumeration (enum) is a user-defined data type that assigns names to integer constants.
Declaration of Enumeration
Example of Enumeration
Using Enumeration Variables
Example Program (Enumeration)
Advantages of Enumeration
-
Improves code readability
-
Reduces use of numeric constants
-
Easy maintenance
Summary
-
Union shares memory among members
-
Structure vs Union differ in memory allocation
-
Enumeration represents named integer constants
-
Both are user-defined data types
🔒 Some advanced sections are available for Registered Members
Register Now
Register Now
Share this Post
← Back to Tutorials