Anonymous Unions : Union « Data Type « C++






Anonymous Unions

Anonymous Unions

#include <iostream>
#include <cstring>

using namespace std;

int main()
{

  union {
    long l;
    double d;
    char s[4];
  } ;

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


           
       








Related examples in the same category

1.Use union to swap bytesUse union to swap bytes
2.Defining and using union WordByteDefining and using union WordByte