What is the difference of writing:
case '1' or case 1
case 'a' or case a
'1' is a character constant, and its value is the encoding for that character (49 in ASCII). So writing
is equivalent to writing
on an ASCII system.
case '1': when you want to take a particular action on seeing the character
case 1: when you want to take a particular action on seeing the integer value
Note that you can't write
case a: if
a is a variable; all case labels must be constant expressions, meaning their value must be known at compile time. This means a case label needs to be an expression consisting only of integer or character constants (or macros that evaluate to such). So the only way
case a: would be legal is if
a is a macro that expands to a constant expression.