If the break statement is not used in a switch case in C, the code will continue to execute the next case statement(s) after a match is found.
For example:
switch (x) { case 1: printf("Case 1"); case 2: printf("Case 2"); case 3: printf("Case 3"); }
If the value of x is 1, the output will be "Case 1Case 2Case 3". This is because after the first match, the code continues to execute the next case statements, instead of breaking out of the switch statement with the use of the break statement.
To avoid this problem, the break statement should be used at the end of each case block.
switch (x) { case 1: printf("Case 1"); break; case 2: printf("Case 2"); break; case 3: printf("Case 3"); break; }
This way, when the program reaches the matching case, it will break out of the switch statement and will not execute any other cases.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.