title: Scope of enum in C vs C++
body: <p>Why are enum values accessible outside the block in which enum is defined in C, but not in C++?</p>
  
  <p>Consider the following C program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  struct mystruct
  {
      enum {INT, FLOAT, STRING} type;
      int integer;
      float floating_point;
  } tu;
  
  /* Why is INT accessible here? */
  int main()
  {
      tu.type = INT;
      tu.integer = 100;
      return 0;
  }
  </code></pre>
  
  <p>It compiles and runs fine in C.</p>
  
  <p>But in C++ it fails in compilation.</p>
  
  <pre><code>#include &lt;iostream&gt;
  struct mystruct
  {
      enum {INT, FLOAT, STRING} type;
      int integer;
      float floating_point;
  } tu;
  
  /* Why is INT accessible here? */
  int main()
  {
      tu.type = INT;
      tu.integer = 100;
      return 0;
  }
  </code></pre>
  
  <blockquote>
    <p>[Error] 'INT' was not declared in this scope</p>
  </blockquote>
  
  <p>Are enum and scope rules different in C and C++?</p>