About the switch
-
situation
Pay attention to the following points when using statements:
The formula in parentheses after (1)switch becomes a "control expression", which can be a variable name (such as a) or an expression, just like a+b in your question.
(2)case must be followed by an exact value, not a variable name. And this exact value only supports two types, plastic and characters. For example: 1 2300, this is all cosmetic surgery,' a',' b'
\n ',
Such single quotation marks become character types. Only these two types are supported after case, and nothing else is supported, such as floating-point numbers (for example, 1.0).
So the D in your question is correct. Switch can be followed by an expression a+b, and in the second case, it can be followed by 1+2. It seems to be a formula, but it is actually a very accurate value of 3, so it is also correct.
Error reason of A: case is followed by floating-point types 1.0 and 2.0;
Error reason of B: case can only be followed by a numerical value, and the form of case 1 2 is incorrect. If you really want to express this meaning, you can do this:
Switch (x)
case
1: case
2:printf(" * \ n ");
case . 3:printf(" * * \ n ");
}
That is to say, just change the comma into a colon, so that the same statement printf ("* \ n") will be executed regardless of whether 1 or 2 is detected;
Error reason of c: 2*a is not an accurate value, so it is incorrect. But if it's a case,
2*3, which is correct, because when the compiler reads statement 2*3, it is equivalent to reading case.
6, in line with the usage of case.
Hehe, that's probably it. Leave a message if you don't understand, and I will always pay attention to your problem.
Ask and answer questions ~
I wish you an early solution to the problem and become a master programmer!