Break Statement MCQ in C

Q1) The keyword ‘break’ cannot be simply used within ______.

a) do-while
b) if-else
c) for
d) while

View Answer Answer:- b) if-else

Q2) The ‘break’ statement is used to exist from.

a) a do loop
b) a for loop
c) a switch statement
d) All of the above
e) None of the above

View Answer Answer:- d) All of the above

Q3) Choose a correct statement about C language break; statement.

a) A single break; statement can force execution control to come out of only one loop.
b) A single break; statement can force execution control to come out of a maximum of two nested loops.
c) A single break; statement can force execution control to come out of a maximum of three nested loops.
d) None of the above.

View Answer Answer:- a) A single break; statement can force execution control to come out of only one loop.

Q4) What is the output of the given below program?

#include<stdio.h>
int main()
{
   for (int i=0; i<5; i++)
   {
      if (i > 2)
         break;
      printf("Know Program \n");
   }
}

a) Know Program is printed 2 times.
b) Know Program is printed 3 times.
c) Know Program is printed 5 times.
d) Know Program is printed infinite times.
e) Compiled Successfully, No Output

View Answer Answer:- b) Know Program is printed 3 times.

The if-block is executed when i = 3. And the printf() statement will be executed when i = 0, 1, and 2. Therefore “Know Program” will be displayed three times. The printf() statement is not part of the if-block.

Q5) What is the output of the given below program?

#include<stdio.h>
int main()
{
   for (int i=0; i<5; i++)
   {
      if (i > 0)
         break;
      printf("Know Program \n");
   }
}

a) Know Program is printed 1 time.
b) Know Program is printed 5 times.
c) Compiled Successfully, No Output
d) Compile-time error

View Answer Answer:- a) Know Program is printed 1 time.

The if-block is executed when i = 1, and the printf() statement is executed when i = 0. Therefore the printf() executes only 1 time.

Q6) Find the output of the given program?

#include<stdio.h>
int main()
{
   for (int i=0; i<5; i++)
   {
      if (i > 0)
         break;
         break;
      printf("Know Program \n");
   }
}

a) Know Program is printed 1 time.
b) Know Program is printed 5 times.
c) Compiled Successfully, No Output
d) Compile-time error

View Answer Answer:- c) Compiled Successfully, No Output

There are two “break” statements. The 1st “break” is part of the if-block and it will execute only when (i > 0), but the 2nd “break” statement is not part of the if-block, it is a valid statement inside for loop and it can execute on any iteration. When i = 0, then if-condition becomes false and if-block won’t be executed. After that “break” (2nd break) is there which will be executed and control came out of the loop. The printf() statement never got a chance to execute.

Q7) What is the output of the given below program?

#include<stdio.h>
int main()
{
   for (int i=1; i<3; i++)
   {
      for (int j=1; j<3; j++)
      {
         if (i > 5)
         break;
      }
      printf("Know Program \n");
   }
}

a) Know Program is printed 2 times.
b) Know Program is printed 3 times.
c) Know Program is printed 5 times.
d) Know Program is printed infinite times.
e) Compiled Successfully, No Output

View Answer Answer:- a) Know Program is printed 2 times.

The printf() statement is part of the outer for loop, but not the part of the inner for loop. Therefore execution of printf() completely depends upon the outer for loop. The outer for loop is executed 2 times therefore “Know Program” will be printed 2 times.

Q8) Find the output of the given program?

#include<stdio.h>
int main()
{
   int x=0;
   for (int i=1; i<3; i++)
   {
      x++;
      if (i == 2)
         break;
      printf("Know Program \n");
   }
}

a) Know Program is printed 3 times.
b) Know Program is printed 2 times.
c) Know Program is printed 1 time.
e) Compile-time error

View Answer Answer:- c) Know Program is printed 1 time.

The if-block will be executed when i == 2. And printf() statement will be executed when i = 1. Therefore the “Know Program” will be displayed only 1 time.

Q9) Find the output of the given program?

#include<stdio.h>
int main()
{
   int i=0;
   while (i<5)
   {
      if (i == 1)
         break;
      i++;
      if (i == 5)
         continue;
      printf("Know Program \n");
   }
}

a) Know Program is printed 1 time.
b) Know Program is printed 4 times.
c) Know Program is printed 5 times.
d) Compiled Successfully, No Output
e) Compile-time error

View Answer Answer:- a) Know Program is printed 1 time.

On each iteration, the “i” value is incremented by 1. The “break” statement is executed when i == 1, and the “continue” statement will be executed when i == 5. When i = 0, then both if-condition becomes false and printf() statement got chance to execute. On the next iteration, i = 1, and the first if-condition becomes true therefore “break” statement is executed and control came out of the loop.

Q10) Find the output of the given program?

#include<stdio.h>
int main()
{
   int i=0;
   while (i<5)
   {
      if (i == 1)
         break;
      i++;
      if (i == 1)
         continue;
      printf("Hello \n");
   }
   printf("Know Program \n");
}

a) Hello
b) Know Program

c)
Hello
Know Program

d)
Hello
Hello
Knowprogram

View Answer Answer:- b) Know Program

Q11) What is the output of the given below program?

#include<stdio.h>
int main()
{
   int i=0;
   char c = 'Z';

   while (i<5)
   {
      i++;
      switch (c)
      {
         case 'Z': 
            printf("%c", c);
            
            break;
      }
   }
}

a) Z
b) Z Z Z Z
c) Z Z Z Z Z
d) None of these

View Answer Answer:- c) Z Z Z Z Z

Q12) What is the output of the given below program?

#include<stdio.h>
int main()
{
   int i=0;
   while (i<5)
   {
      ++i;
      if (i>=3 && i<=7)
         break;
      printf("%d ", i);
   }
   return 0;
}

a) 1 2
b) 1 2 3 4
c) 4
d) 4 5 6
e) None of these

View Answer Answer:- a) 1 2

Also See:- If-Else Statement MCQ in C

Leave a Comment

Your email address will not be published. Required fields are marked *