Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What's the difference between %f and %d
What's the difference between %f and %d
%d, output according to the actual length of integer data.

%f is used to output real numbers (including single precision and double precision) in decimal form.

For example: 2.5, printf("x=%d ",x); The output is an integer: x=2.

Use printf instead ("x =% f", x); The output is: x=2.5

The following are commonly used format characters:

Characters in (1)d format. Used to output decimal integers.

%d, output according to the actual length of integer data.

%md, m is the width of the specified output field.

%ld, output long integer data.

(2)o format characters, which output integers in the form of octal integers.

(3)x format characters, which output integers in the form of hexadecimal numbers.

(4) The U-format symbol is used to output unsigned data, that is, unsigned numbers, which are output in decimal form.

(5)c format characters, which are used to output a character.

(6) Characters in S format are used to output a string.

(7)f format symbol, which is used to output real numbers (including single precision and double precision) and output in decimal form.

(8)e-format symbols, which output real numbers in exponential form.

(9)g format symbol, which is used to output real numbers. It will automatically select F format or E format according to the size of the value.

(10)p format character, used for the output of variable address.

References:

Format Characters-Baidu Encyclopedia