title: Creating a bit sized variable
body: <p>I wanted to create a bit sized variable to save the only possible values 2^1 = 0 | 1</p>
  <p>My initial approach was to create a class with variables of type int for storing the value 0 | 1</p>
  <p>But then i found that i could also use a bitfield and also create my own struct with custom bits for each type. My question is that does using a struct with bits set to 1 provide better memory performance and hence faster implementation than the class approach for a array of struct like ( 4000 x 4000 )</p>
  <p>The code :</p>
  <pre class="lang-cpp prettyprint-override"><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  struct maze
  {
      unsigned int top : 1;
      unsigned int right : 1;
      unsigned int bottom : 1;
      unsigned int left : 1;
  };
  
  int main()
  {
      maze access;
      
      cout&lt;&lt;sizeof(access);
  
      access.top=1;
      access.right=1;
      access.bottom=1;
      access.left=1;
  
      cout&lt;&lt;endl&lt;&lt;sizeof(access);
  
      return 0;
  }
  </code></pre>
  <p>Edit:</p>
  <p>I think i have found the answer : <a href="https://stackoverflow.com/a/46544000/13868755">https://stackoverflow.com/a/46544000/13868755</a></p>