Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In a <code>switch-case</code> construct, the <code>switch</code> body is just a normal or compound statement which can contain any other valid c statements. It may also contain <code>case</code> or <code>default</code> labels.<br> And the control jumps to appropriate case label depending on controlling expression value, the statements in the switch body are executed one after another just like any other scope <code>{</code> <code>}</code> unless a <code>break</code> is encountered. </p> <p>For example, consider the following <strong><a href="http://ideone.com/e24yJ" rel="nofollow">simple test program</a></strong>:</p> <pre><code>#include&lt;stdio.h&gt; int main() { int i = 6;//5,10; switch(6) { case 10: printf("\nIn case 10"); case 11: printf("\nIn case 11"); case 12: printf("\nIn case 12"); break; case 5: printf("\nIn case 5"); break; case 6: printf("\nIn case 6"); default: printf("\nIn Default"); } return 0; } </code></pre> <p>Consider 3 values for the controlling expression <code>i</code> in the <code>switch</code> statement: </p> <pre><code>5 6 10 </code></pre> <p>The resultant outputs are as follows:<br> <strong>Scenario 1:</strong> <code>i = 6</code></p> <pre><code>In case 6 In Default </code></pre> <p><strong>Scenario 2:</strong> <code>i = 10</code></p> <pre><code>In case 10 In case 11 In case 12 </code></pre> <p><strong>Scenario 3:</strong> <code>i = 5</code> </p> <pre><code>In case 5 </code></pre> <p>Notice that, in each of the above scenarios, once a matching <code>case</code> label is encountered the statements are executed sequentially until a <code>break</code> is encountered, Thereby leading to conclusion which is the first statement in the answer.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload