Anonymous union : Union Class « Class « C++






Anonymous union

   
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
  union{
    long l;
    double d;
    char s[4];
  };

  l = 100000;
  cout << l << " ";
  d = 123.2342;
  cout << d << " ";
  strcpy(s, "hi");
  cout << s;
}
  
    
    
  








Related examples in the same category

1.Use union to define classUse union to define class
2.Unions and Classes are Related
3.An anonymous union is a union that has neither a tag name nor any objects specified in its declaration.