What is the purpose of the default case in a switch statement?

  • It defines a fallback case
  • It specifies the first case
  • It is used for loop control
  • It marks the end of the switch
The default case in a switch statement serves as a fallback option. If none of the other cases match the expression's value, the code in the default case block is executed. This ensures that there is always a valid path in the switch.
Add your answer
Loading...

Leave a comment

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