Reference blog: https: //blog.csdn.net/sinat_34009734/article/details/51646469
printf output format: % [the flags] [width] [. PERC] [F. | N | H | L] type
Uses the flags 0 (note is not zero ohms), which is described as Wikipedia: The front fill output 0 until filled up to the specified column width (not used with -)
width means that the number of bits required output.
- int a = 4;
- printf("%03d",a);
Output: 004
Can also be used instead of bits * in the parameter list used later to control the output variable number of bits;
- int a = 4;
- int n = 3;
- printf("%0*d",n,a);
Output: 004
Such as:
int main ()
{
char C, S [20 is];
int A = 1234;
a float F = 3.141592653589;
Double X = .12345678912345678;
strcpy (S, "the Hello, World");
C = '\ X41';
the printf ( "A =% D \ n- ", a); // a decimal integer output format, display = 1234 A
the printf ("% D A = %% \ n-", a); // output% = 1234% results A
the printf ("% A 6D = \ n ", a); // output six decimal integer fill the space left, the display 1234 a =
the printf ("% a = 06D \ n ", a); // left six decimal integer output 0s, display a = 001 234
the printf ( "% A = 2D \ n-", A); // A more than two, according to the actual output = 1234 A
the printf ( "% = A - 6D \ n-", A); /// decimal output 6 integer up space on the right, the display = 1234 A
the printf ( "% F = F \ n-", F); // float 7 is a valid number, the result = 3.141593 F
the printf ( "F = 6.4f \ n-", F) ; // output 6, four decimal places, results = 3.1416 F
the printf ( "% X = LF \ n-", X); // float length output = .123457 X
the printf ( "X =% 18.16lf \ n-" , x);// output 18, 16 after the decimal point, X = 0.1234567891234567
the printf ( "% C = C \ n-", C); // output character c = A
printf ( "c =% x \ n", c); // c = 41 in ASCII hexadecimal characters output
printf ( "s [] =% s \ n", s); // output character array string S [] = the Hello, World
the printf ( "S [] = 6.9s% \ n-", S); // outputs s 9 up character string [] = Hello, Wor
int A = 1234;
a float F = 3.141592653589;
Double X = .12345678912345678;
strcpy (S, "the Hello, World");
C = '\ X41';
the printf ( "A =% D \ n- ", a); // a decimal integer output format, display = 1234 A
the printf ("% D A = %% \ n-", a); // output% = 1234% results A
the printf ("% A 6D = \ n ", a); // output six decimal integer fill the space left, the display 1234 a =
the printf ("% a = 06D \ n ", a); // left six decimal integer output 0s, display a = 001 234
the printf ( "% A = 2D \ n-", A); // A more than two, according to the actual output = 1234 A
the printf ( "% = A - 6D \ n-", A); /// decimal output 6 integer up space on the right, the display = 1234 A
the printf ( "% F = F \ n-", F); // float 7 is a valid number, the result = 3.141593 F
the printf ( "F = 6.4f \ n-", F) ; // output 6, four decimal places, results = 3.1416 F
the printf ( "% X = LF \ n-", X); // float length output = .123457 X
the printf ( "X =% 18.16lf \ n-" , x);// output 18, 16 after the decimal point, X = 0.1234567891234567
the printf ( "% C = C \ n-", C); // output character c = A
printf ( "c =% x \ n", c); // c = 41 in ASCII hexadecimal characters output
printf ( "s [] =% s \ n", s); // output character array string S [] = the Hello, World
the printf ( "S [] = 6.9s% \ n-", S); // outputs s 9 up character string [] = Hello, Wor
return 0;
}