Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - The change of variable type in C language leads to output error?
The change of variable type in C language leads to output error?
be

First, in the printf () function, if you output a variable in the format of other variable types, it will often lead to wrong results.

For example:

int a = 5; //define the integer variable a.

printf("%f ",a); //Output in floating-point format

You won't get 5 or 5.0000 (the last few zeros), but you will get gibberish.

Second, there is only one exception, that is, character variables can be output as integers, and ASC codes of characters will be output.

For example:

char a = ' A

You can output the following two sentences normally:

printf("%c ",a); //The character: a will be output.

printf("%d ",a); //The ASC code of the character A will be output: 65.

Three, unless necessary, generally do not use other formats to output, so as not to lead to errors.