1. What is the purpose of the 'switch' statement in C?
Answer:
Explanation:
The 'switch' statement in C is used to select and execute one code block from multiple choices based on the value of a variable.
2. Which type of expression can be used in a C 'switch' statement?
Answer:
Explanation:
The expression used in a 'switch' statement must be an integer or a character (which is internally represented as an integer).
3. What keyword is used to define cases in a 'switch' statement in C?
Answer:
Explanation:
The 'case' keyword is used to define different cases in a 'switch' statement in C.
4. What is the role of the 'break' statement in a 'switch' case in C?
Answer:
Explanation:
The 'break' statement is used to exit the switch statement and to prevent the execution from falling through to the next case.
5. What will happen if the 'break' statement is omitted in a 'switch' case in C?
Answer:
Explanation:
If the 'break' statement is omitted, the execution will "fall through" and continue into the next case until a 'break' is encountered or the switch ends.
6. What keyword is used to define a default case in a 'switch' statement?
Answer:
Explanation:
The 'default' keyword is used to define a case that will be executed if none of the other cases match.
7. How many 'default' cases can a 'switch' statement have in C?
Answer:
Explanation:
A 'switch' statement can have only one 'default' case, which is executed if no other case matches.
8. What is the correct syntax for a 'switch' statement in C?
Answer:
Explanation:
The correct syntax for a 'switch' statement includes the 'switch' keyword followed by an expression in parentheses, and then one or more 'case' statements.
9. Can a 'switch' statement in C be nested inside another 'switch' statement?
Answer:
Explanation:
'Switch' statements can be nested, meaning one switch can be placed inside another.
10. Which of the following is a valid use of a 'switch' statement in C?
Answer:
Explanation:
'Switch' statements are commonly used to execute different blocks of code based on the value of a character or integer variable.
Comments
Post a Comment