• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Quiz - 105

Question 1

Choose the best statement with respect to following three program snippets.
C
<br>
/*Program Snippet 1 with for loop*/<br>
for (i = 0; i < 10; i++)<br>
{<br>
   /*statement1*/<br>
   continue;<br>
   /*statement2*/<br>
}<br>

/*Program Snippet 2 with while loop*/<br>
i = 0;<br>
while (i < 10)<br>
{<br>
   /*statement1*/<br>
   continue;<br>
   /*statement2*/<br>
   i++;<br>
}<br>

/*Program Snippet 3 with do-while loop*/<br>
i = 0;<br>
do<br>
{<br>
   /*statement1*/<br>
   continue;<br>
   /*statement2*/<br>
   i++;<br>
}while (i < 10);<br>

  • All the loops are equivalent i.e. any of the three can be chosen and they all will perform exactly same.
  • continue can't be used with all the three loops in C.
  • After hitting the continue; statement in all the loops, the next expression to be executed would be controlling expression (i.e. i < 10) in all the 3 loops.
  • None of the above is correct.

Question 2

In the context of "break" and "continue" statements in C, pick the best statement.
  • “break” can be used in “for”, “while” and “do-while” loop body.
  • “continue” can be used in “for”, “while” and “do-while” loop body.
  • “break” and “continue” can be used in “for”, “while”, “do-while” loop body and “switch” body.
  • “break” and “continue” can be used in “for”, “while” and “do-while” loop body. But only “break” can be used in “switch” body.
  • “break” and “continue” can be used in “for”, “while” and “do-while” loop body. Besides, “continue” and “break” can be used in “switch” and “if-else” body.

Question 3

What would happen when we compile and run this program?
C
<br>
#include < stdio.h ><br>
int main()<br>
{<br>
  int i; <br>
  goto LOOP;<br>
  for (i = 0 ; i < 10 ; i++)<br>
  {<br>
     printf(\"GeeksQuiz &#92;n\");<br>
     LOOP:<br>
      break;<br>
  }<br>
  return 0;<br>
}<br>

  • No compile error and it will print GeeksQuiz 10 times because goto label LOOP wouldn’t come in effect.
  • No compile error and it’ll print GeeksQuiz only once because goto label LOOP would come in picture only after entering for loop.
  • Compile Error because any goto label isn’t allowed in for loop in C.
  • No compile error but behaviour of the program would depend on C compiler due to nondeterministic behaviour of goto statement.
  • No compile error and it will not print anything.

Question 4

A typical “switch” body looks as follows:
C
<br>
switch (controlling_expression)<br>
{<br>
  case label1:<br>
    /*label1 statements*/<br>
    break;<br>
  case label2:<br>
    /*label1 statements*/<br>
    break;<br>
  default:<br>
    /*Default statements*/<br>
}<br>

Which of the following statement is not correct statement?
  • “switch” body may not have any “case” label at all and it would still compile.
  • “switch” body may not have the “default” label and it would still compile.
  • “switch” body may contain more than one “case” labels where the label value of these “case” is same and it would still compile. If “switch” controlling expression results in this “case” label value, the “case” which is placed first would be executed.
  • “switch” body may not have any “break” statement and it would still compile.
  • “switch” body can have the “default” label at first i.e. before all the other “case” labels. It would still compile.

Question 5

Which of the following is correct with respect to “Jump Statements” in C?
  • goto
  • continue
  • break
  • return
  • All of the above.

There are 5 questions to complete.

Last Updated :
Take a part in the ongoing discussion