well In structure you can think up like a class that when an object is created
it consist of all the data members declared in it .
say class A{
int a;
float b;
char c;
}
so when you create an object say A obj= new A();
it will occupy 2 bytes for int +4 bytes for float+1 byte for char so in total 8 bytes
where as in Union it will occupy the bytes of the
highest data type say here is float so it will occupy only 4 bytes.
------------------------------------------------------------------------------------
A good example is when you have a data file with a fixed-size record,
but the record may contain different things. For instance,
one record may contain 64 characters of text.
Another record may contain 16 4-byte integers.
You may then have something like
typedef struct
{
int record_type;
union
{
char text[64];
int values[16];
}
} RECORD;
In this example, the struct member record_type can be used to determine
if the data are to be read as a text string or as an array of integer values.
To embed this program on your website, copy the following code and paste it into your website's HTML: