Format of printf

1) Type
type character is used to indicate the type of output data, and its format and meaning are shown in the following table:

%c prints a single character 

%s output string

%u outputs an unsigned integer in decimal

%d outputs signed integers in decimal form (positive numbers do not output signs)

%lld means output as a decimal long integer;

%o output unsigned integer in octal (do not output prefix 0)

%x output unsigned integer in hexadecimal form (without output prefix Ox)

%f outputs single and double precision real numbers in decimal form

%lf long floating point is double

%e%E print single and double precision real numbers in exponential form

%g%G output single and double precision real numbers with the shorter output width of %f or %e

%p 

 2) Logo

- The result is left-aligned, with spaces on the right

+ output sign (plus or minus)

space The output value is prefixed with a space when the output value is positive, and a minus sign when it is negative

# has no effect on classes c, s, d, and u;
         for class o, prefix o when outputting;
         for class x, add prefix 0x when outputting ; for classes
         e, g, and f, it is only given when the result has decimals decimal point.

3) Output minimum width
Use decimal integer to represent the minimum number of output digits. If the actual number of digits is more than the defined width, it will be output according to the actual number of digits. If the actual number of digits is less than the defined width, a space or 0 will be added.

%02d

%02x

4) Precision
The precision format specifier begins with "." followed by a decimal integer. The meaning of this item is: if the output is a number, it means the number of decimal places; if the output is a character, it means the number of output characters; if the actual number of digits is greater than the defined precision, the excess part will be truncated.

%.nf

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325032080&siteId=291194637