title: How do flags work in C?
body: <p>Recently I have come across several examples of "flags" in C and C++, and I don't quite understand how they work. After looking at some source code I noticed that often flag values are defined in hexadecimal such as the following:</p>
  
  <pre><code>FLAG1 = 0x00000001,
  FLAG2 = 0x00000010,
  </code></pre>
  
  <p>My intuitive suggests that these values are being combined. Do flags work by combining all the flags values into one int? If I had used both of these like <code>FLAG1 | FLAG2</code> would the result be <code>0x00000011</code>?</p>
  
  <p>Do I need to create enums with bit offsets or can I use ascending integers Like:</p>
  
  <pre><code>FLAG1 = 1;
  FLAG2 = 2;
  </code></pre>