VOOZH about

URL: https://www.geeksforgeeks.org/c/data-type-of-case-labels-of-switch-statement-in-c/

⇱ Data type of case labels of switch statement in C++? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Data type of case labels of switch statement in C++?

Last Updated : 12 Aug, 2021

In C++ switch statement, the expression of each case label must be an integer constant expression. 
For example, the following program fails in compilation. 
 

Putting const before i makes the above program work.
 

Note : The above fact is only for C++. In C, both programs produce an error. In C, using an integer literal does not cause an error.
Program to find the largest number between two numbers using switch case:
 


 

Comment
Article Tags: