Advertisement
Felanpro

Union, Example: 2

Jul 1st, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 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;
  19.  
  20.     pill_object.blue_pill == false;
  21.  
  22.     if(pill_object.red_pill)
  23.     {
  24.         cout << "You survived." << endl;
  25.     }
  26.     else
  27.     {
  28.         cout << "You died." << endl;
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement