Home » C Programming » Control Instructions

Point out the error, if any in the program. #include int main() { int P = 10; switch(P) { case 10: printf("Case 1"); case 20: printf("Case 2"); break; case P: printf("Case 2"); break; } return 0; }

Correct Answer: Error: Constant expression required at line case P:

Explanation:

The compiler will report the error "Constant expression required" in the line case P: . Because, variable names cannot be used with case statements.


The case statements will accept only constant expression.


← Previous Question Next Question→

More Questions from Control Instructions

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion