Home > Back-end >  Novice small white, want to ask, where is wrong
Novice small white, want to ask, where is wrong

Time:05-24

CodePudding user response:

Case 'b> Max ': this type is wrong,' b> Max "is what type, not character, also is not a string, the back of the case with plastic,

CodePudding user response:

Reference:
 # include 

Int main ()
{
Int a, b, c;
Printf (" please enter the number three: \ n ");
The scanf (" % d % d % d ", & amp; A, & amp; B, & amp; C);
Printf (" maximum: % d \ n ", a> b? (a> c? A: c) : (b> c? B, c));

return 0;
}

CodePudding user response:

Thank you, hey hey

CodePudding user response:

refer to the second floor QZJHJXJ response:
case 'b> Max ': this type is wrong,' b> Max "is what type, not character, also is not a string, the back of the case with plastic,

This statement is not true,

First of all, the back of the case have to integer constant expression (rather than the usual sense of the integer),

Second, 'b> Max 'is the character constants, it is of type int, therefore,' b> Max 'is of type int, based on the definition of integer constants expression,' b> Max 'is integer constant expressions,

So the case 'b> Max 'there is no problem on grammar,

Where is the problem? Character constants for single characters, such as' x ', converted to int type of character encoding at compile time, however, to include more than one character constants of the characters, such as' abcd ', how to package into int type code at compile time, determined by the compiler (C), there are a lot of machine, the length of the int type is 4 bytes, would be four characters, but more than four characters will appear warning,

Look at the example below, this example can be normal execution and print "Okay." :
 switch (' b> Ma ') 
{
Case 'b> Ma ': printf (" Okay. \ n ");
}

In many machines, this example does not produce "character is too long" warning, but likely "character constants is composed of multiple characters" warning, but relative to character is too long warned, behind a warning is acceptable,

CodePudding user response:

Guess, what content to the following program fragment will be printed?
 int m=5; 

The switch (0)
{
M + +;
Default: printf (" % d \ n ", m);
}
  • Related