Bird
0
0

What will be the output of this C code?

medium📝 Predict Output Q4 of 15
C - onditional Statements
What will be the output of this C code?
int n = 3;
switch (n) {
  case 1: printf("One\n"); break;
  case 2: printf("Two\n"); break;
  default: printf("Other\n");
}
AOne
BOther
CTwo
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Check the value of n

    Variable n is 3, which does not match case 1 or 2.
  2. Step 2: Determine which case executes

    Since no case matches, the default case runs, printing "Other".
  3. Final Answer:

    Other -> Option B
  4. Quick Check:

    Default case output = B [OK]
Quick Trick: Default runs if no case matches in switch [OK]
Common Mistakes:
  • Assuming case 1 or 2 runs
  • Forgetting default case runs
  • Expecting no output without break

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes