In a switch statement, if a break statement is missing, _______________. Select one: a. the default case is automatically executed b. the break happens at the end of each branch by default c. execution falls through the next branch until a break statement is reached d. the statement will not compile

Respuesta :

Answer:

c. execution falls through the next branch until a break statement is reached

Explanation:

In a switch statement, if break is missing, then program continues to the next cases until it finds a break statement.

Consider the following example!

Example:

#include <iostream>

using namespace std;

int main()

{

  int choice = 1;

  switch (choice)

  {

      case 1:

      printf("This is case 1, No break\n");

      case 2:

      printf("This is case 2, No break\n");

      case 3:

      printf("This is case 3, with break\n");

      break;

      default: printf("Error! wrong choice\n");

  }

  return 0;

}

Output:

This is case 1, No break

This is case 2, No break

This is case 3, with break

We have 3 cases here and case 1 and 2 don't have break statements, only case 3 has a break statement.

We called the case 1, then program continued to case 2,  and finally to case 3 where it finds the break statement and terminates.

Therefore, we conclude that in a switch statement, if a break statement is missing, then execution falls through the next branch until a break statement is found.