An anonymous union is a union that has neither a tag name nor any objects specified in its declaration. : Union Class « Class « C++






An anonymous union is a union that has neither a tag name nor any objects specified in its declaration.

  
#include <iostream>  
using namespace std;

main(void)  
{  
  union {  
    int i;  
    char ch[2];  
  } ;
     
  /* Now reference i and ch without referencing  
     a union name or dot or arrow operators.  
  */  
  i = 88;  
  cout << i << " " << ch[0];  
     
  return 0;  
}
  
    
  








Related examples in the same category

1.Use union to define classUse union to define class
2.Unions and Classes are Related
3.Anonymous union