It is well known that a structure is a heterogeneous data type which allow to pack together different types of data values as a single unit.  Union is also similar to a structure data type with a difference in the way the data is stored and retrieved.  The union stores values of different types in a single location.  A union will contain one of many different types of values.   
 
The general form of union is 
 
  union user_defined_name{
   member1;
   member 2;
   _________
   __________
   member n; 
  };
the keyword union is used to declare the union data type. This is followed by a user_defined_name surrounded by braces which describes the member of the union. 

Example:

 union sample{ 
   int x;
   char s;
   float t; 
  } one, two;
where one and two are the union variables similar to data size of the sample. 

It is possible to define a union data type without a user_defined_name or tag and this type of declaration is called an anonymous union.
The general form is 

union{
  member1;
  member2;
  __________;
  __________;
  member n;
}; 
The keyword union is used to declare the union data type. This is followed by braces which describes the member of the union. 
 
 Eg.
union{ 
  int x; 
   float a;
  char ch; 
  }; 

Sample program: 
 
 #include <iostream.h>
 void main(void)
 {
  union
  { 
   int x;
   float y;
   cout<<"enter the following information"<<endl;
   cout<<"x(in integer)"<<endl;
   cin>>x; 
   cout<<"y(in floating)"<<endl;
   cin>>y;
   cout<<"\n content of union"<<endl;
   cout<<"x="<<x<<endl;
   cout<<"y="<<y<<endl;
  } 
 the output is 
  enter the following information 
x(in integer)
  10
  y(in floating)
  34.90
  content of union
  x=10
  y=34.90