A union is a variable that can hold objects of various types and sizes, with the compiler taking track of the size and alignment needs. It allows you to modify several types of data in a single storage location without including any machine-dependent information in the program.
In this part, we just declare the union's template, which includes the names of the members and their data types, as well as the union's name. The declaration allocates no memory to the union.
To use union members, we must first define a union-type variable. There are two approaches to defining a union variable.
The union's size will always be the same as that of the array's largest member. All of the smaller elements can store data in the same place without exceeding their capacity.
An enumeration (enum) is a user-defined type (similar to structure) that represents a collection of constants. An enum is a user-defined data type that allows a variable to take only one of the specified values. Assigning names to integral constants improves program readability and maintainability.
Enums in C are used when a variable has a defined set of possible values that will never change, offering a simple and easy way to deal with such constants. This improves code readability and reduces error rates.