Advertisement
Felanpro

Union, Example: 1

Jul 1st, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.     union Pill
  10.     {
  11.         bool red_pill;  //Pointer----|
  12.         bool blue_pill; //Pointer--------[Memory-Address]
  13.         bool green_pill;//Pointer----|
  14.     };
  15.  
  16.     Pill pill_object;
  17.  
  18.     pill_object.red_pill = true;
  19.  
  20.     if(pill_object.red_pill)
  21.     {
  22.         cout << "You survived." << endl;
  23.     }
  24.     else
  25.     {
  26.         cout << "You died." << endl;
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement