The results in switch () brackets use n of case n: to determine the turn.
N is an integer, so you must have an integer arithmetic expression.
Character quantity (not string) can be regarded as integer quantity, such as' a' and' x', so it can be used.
The outputs of logical expressions, "true" and "false" are essentially 1 and 0. When used in the parentheses of switch (), you will get a compilation warning error message, because it does not meet the syntax requirements, but it can run correctly.
For example:
Printf ("enter a, b \ n");
Scanf("%f %f ",&i, & b);
Switch (a>b ){
Case 0: printf("a+b=%f\n ",a+b); Break;
Case 1: printf("a-b=%f\n ",a-b); Break;
default:printf(" default \ n "); Break;
}
Switch ('x'+ 1 ){
Case 0: printf("x: a+b=%f ",a+b); Break;
case 1: printf("x: a-b=%f ",a-b); Break;
default:printf(" x:default \ n "); Break;
}
For our general use, just remember to use only integer arithmetic expressions.