Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How does switch use strings as conditional expressions in C language?
How does switch use strings as conditional expressions in C language?
First, the type expressions of switch statements and case must be integers, characters or enumeration values.

Super curiously compiled:

1 & gt; E: \ project \ STL _ proc \ STL _ proc \ STL _ proc \ STL _ proc.cpp (86): Error C2052: "double": illegal case expression type.

Really subverted my three views. . . . The switch ("0.4") did not report an error. . After I have solved the following problem, let's see how the program handles it.

Change to:

Switch ("0.4")

{

Case "0": a = 0; Break;

Case ".":a = 9;; Break;

Default: a = 7;;

}printf("%d ",a);

After running, all go to the default branch.

Change to:

Switch ("0")

{

Case "0": a = 0; Break;

Case ".":a = 9;; Break;

Default: a = 7;;

}printf("%d ",a);

They all went to the case 0 branch.

Conclusion: switch cannot be followed by variables.