The C and C++ code snippets monologue forum

The C, C++, Code, Coder, Coding Snippets Zone for Tenouk.com

 

 
It is currently Thu Sep 09, 2010 8:15 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: The u.n.i.o.n data type
PostPosted: Sat Nov 18, 2006 12:16 pm 
Offline

Joined: Sat Nov 11, 2006 1:15 pm
Posts: 280
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Displaying some values
To show: The u.n.i.o.n data type


Code:
// The union data type
#include <iostream>
using namespace std;

union Num
{
   int      ValueI;
   float    ValueF;
   double   ValueD;
   char   ValueC;
};

void main()
{
   // Optional union keyword
   // ValueI = 100
   Num TestVal = {100};

   cout<<"\nInteger = "<<TestVal.ValueI<<endl;
   TestVal.ValueF = 2.123L;
   cout<<"Float = "<<TestVal.ValueF<<endl;
   cout<<"Uninitialzed double = "<<TestVal.ValueD<<endl;
   cout<<"Some rubbish???"<<endl;
   TestVal.ValueC = 'U';
   cout<<"Character = "<<TestVal.ValueC<<endl;
}


Output:

Code:
Integer = 100
Float = 2.123
Uninitialzed double = 5.30754e-315
Some rubbish???
Character = U
Press any key to continue . . .

_________________
None


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane