These are format characters
Use different format characters when outputting different data
%d is used to output decimal integer data The actual length is output
%c is output in character form, only one character is output
%f is output single or double precision degree in decimal form, implicitly outputting 6 decimal places< /p>
There are many more, such as %s (output string) and so on
So how to use it?
For example, when printf outputs data
int n=5;
printf("%d",n);
This way It's output.
Printf function format characters:
In C language, different format characters are used for different types of data. The following format characters are commonly used:
(1) d format character. Used to output decimal integers. There are several usages:
1. %d, output according to the actual length of integer data.
2. %md, m is the width of the specified output field.
3. %ld, output long integer data.
(2) o format character, output integer in octal integer form.
(3) x format character, output integers in the form of hexadecimal numbers.
(4) The u format character is used to output unsigned data, that is, unsigned numbers, output in decimal form.
(5) c format character, used to output a character.
(6) s format character, used to output a string.
(7) The f format character is used to output real numbers (including single and double precision) in decimal form.
(8) e format character, output real numbers in exponential form.
(9) The g format character is used to output real numbers. It automatically selects the f format or the e format according to the size of the value (the selected output is the one with a smaller width), and does not output meaningless of zero.
(10) %[scanfset]:
scanfset has two forms: one is a scanset starting with a non-"^" character, which means that it will match when reading the string For all characters that appear in scanfset, the input ends when encountering characters not in scanfset; another form is scanfset starting with the "^" character, which means that when reading a string, all characters that do not appear in scanfset will be matched. , ends when character input in scanfset is encountered.