title: How does switch statement work?
body: <p>How are statements that come before any <code>case</code> labelled statement in a <code>switch-case</code> block treated.
  Please explain the behavior of the following programs</p>
  
  <p>prog1:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
    switch(1)
    {   
      int i=0; 
      case 1:printf("%d",i);         
    }
  getchar();
  return 0;
  }
  </code></pre>
  
  <p>Output: garbage value.</p>
  
  <p>prog2:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
    switch(1)
    {  
      printf("Inside Switch");  
      case 1:printf("Case 1\n");      
    }
    printf("Outside Switch");
    getchar();
    return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p>Case 1</p>
  
  <p>Outside Switch.</p>
  
  <p>The statements before a case labelled statement seem unreachable according to program 2 but then why don't i get an error for an undeclared variable <code>i</code> in the first program (only a warning).</p>
  
  <p>Would be really helpful if someone could explain in detail that how the <code>switch</code> statement is treated internally. </p>