LearnFrenzy
Sign in Take a free test

Control Instructions · Control Instructions MCQ · Question 12

case 1: int x = 5; – valid in C? Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 12 Back to Exercise

Is a declaration directly after a case label, as in case 1: int x = 5;, valid?

  • A Always valid
  • B Invalid before C23 (a label had to be followed by a statement); valid in C23 Correct
  • C Never valid
  • D Valid only in default
Correct Answer: Option B

Until C17, a label had to label a statement, and a declaration is not one. The usual workaround was braces: case 1: { int x = 5; … }. C23 now allows the declaration directly.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links