Character type, only character constants are allowed. For example,' a' 'b' '6' '\r' is actually an integer.
Boolean type-true, false, actually 0, 1 ... integer.
You can use any expression whose value is an integer.
The enumeration type can also be estimated because it simulates 0, 1, 2, 3. ...
What kind of statement is in parentheses after if in C language? Are you sure you're asking a statement? Anything can be put in curly braces; If it is a bracket, it is an expression, not a statement.
If (expression) statement
If (expression) statement else statement
The expression in parentheses should be of scalar type.
Original text of C99 standard: The control expression of if statement should be scalar type.
Statements can be compound statements, and compound statements are like {...}!
What can be in the brackets of switch () in C language? It can only be an integer arithmetic expression, and everything else does not meet the grammatical requirements.
The results in switch () brackets use n of case n: to determine the turn.
N is an integer, so it must be an integer arithmetic expression.
Character quantity (not string) can be regarded as integer quantity, such as' a' and' x', so it can be used.
Logical expression, the output "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 be executed 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.
In C language, I just tried what type the expression after switch can be. I set the float type, and there was an error during compilation. I said that the expression after switch is not an integer, which means that this expression can only be an integer and a character type. (Because of the numerical characteristics of characters, they can also be regarded as integers. )
What is the type of a pair of bracket expressions after the switch statement in C language? Switch (expression)
Where "expression" refers to any type allowed in the ANSI standard. To put it bluntly, any type you know in C language will do! But overall, integer and character types are used a little more, probably because they are easier to understand and more commonly used than soft ones. The above answer comes from Mr. Tan Haoqiang's C Language Design; Absolute full power!
Why can't the switch () statement in C language use an assignment expression similar to x=4? Although x=4 means assigning a value of 4 to x, it is not what you said. The value of this expression itself is not 4, but the logical value 1, because the expression x=4 is always successful, that is, the value of its expression is true (the logical value is1);
The switch () statement is used to handle a variety of situations. The expression in parentheses can be an integer or a character, with a definite value, but not a logical value.
What data types can flow control switch () have in brackets in C language? The type after case can only be int (or char) or enumeration (or string caused by "").
Therefore, the type in Switch can be int, char, enumeration or reference type string.
What type of condition can be in the switch statement of C language? The condition in the switch statement of C language can be of any type, but generally bool type is not used, because when it is bool type, there will be unpredictable cycles.
The ANSI standard of switch (expression) allows any type of "expression" in C language switch. Generally, all types in C language can be used, but integer and character types are used a little more, which has been mentioned in ANSI standard. If you want to know more details, you can consult the relevant documents: download.chinaprj./detail/rootdbi or download.csdn./source/286783.