Break and Continue in C MCQs Exercise II


Ques 1 Break and Continue


What is output of the following code?


int main()
{
   int k;
   for(i=0;k<5;k++)
   {
      printf("%d",k);
      break;
      printf("Label 1");
   }
   printf("Label 2");
   return 0;
}

  a) 0 Label 1
  b) 0 Label 2
  c) 1 Label 1
  d) 1 Label 2


b is the correct option





Ques 2 Break and Continue


What is output of the following code?


int main()
{
    int k;
    do{
      printf("%d",k);
      continue;
      i++;
    }while(k<=10);
    return 0;
 }
 

  a) 1 2 3 4 5 6 7 8
  b) 0 2 3 4 6 8 9 0
  c) Infinite loop
  d) 0


c is the correct option

The given code contains an infinite loop because the continue statement is placed before the increment of the loop variable k. This means that the loop will keep printing the uninitialized value of k without making any progress.