Bird
0
0

Find the error in this switch statement:

medium📝 Debug Q6 of 15
C - onditional Statements
Find the error in this switch statement:
int val = 1;
switch val {
  case 1:
    printf("One\n");
    break;
  default:
    printf("Default\n");
}
AMissing break statement after case 1
BMissing parentheses around val in switch
CMissing colon after case 1
DMissing semicolon after switch
Step-by-Step Solution
Solution:
  1. Step 1: Check switch syntax

    Switch requires parentheses around the expression: switch(val)
  2. Step 2: Verify other syntax parts

    Break is present, colon after case 1 is correct, no semicolon needed after switch block.
  3. Final Answer:

    Missing parentheses around val in switch -> Option B
  4. Quick Check:

    Switch expression must be in parentheses [OK]
Quick Trick: Always put parentheses around switch expression [OK]
Common Mistakes:
  • Omitting parentheses around switch expression
  • Confusing break with colon syntax
  • Expecting semicolon after switch block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes