Structure is a method of packing data of different types. A structure is a convenient method of handling a group of related data items of different data types.
example:
struct lib_books
{
char title[20];
char author[15];
int pages;
float price;
};
Union:
Unions like structure contain members whose individual data types may differ from one another. However the members that compose a union all SHARE THE SAME STORAGE AREA within the computers memory where as each member within a structure is assigned its own unique storage area. They are useful for application involving multiple members. Where values need not be assigned to all the members at any one time.
Just look in any header file from the Pic30 tools c compiler for a Pic30, Pic33, Pic24 micro.
Most ports or registers are defined as bit fields and also as ints.
You can clear a port by writing 0 to the int or set individual bits by using the bit fields.
They share memory.
Unions are also good when ram space is limited.
Beware though, they are not fully portable.