09 c]How union is different from struct? Give example.
Structure : A structure is a user-defined data type available in C that allows to combining data items of different kinds. Structures are used to represent a record.
Defining a structure: To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than or equal to one member.
Syntax:
struct [structure name]
{
member definition;
member definition;
...
member definition;
};
union :A union is a special data type available in C that allows storing different data types in the same memory location.
Defining a Union: To define a union, you must use the union statement in the same way as you did while defining a structure. The union statement defines a new data type with more than one member for your program.
Syntax:
union [union name]
{
member definition;
member definition;
...
member definition;
};
Difference between Structure and Union: