D format character: used to output a signed decimal integer
D The previous number indicates the width of the field (the number of columns), such as%5d specified data accounted for 5 columns, the output of data in 5 columns of the right
If the output is long, add the letter L, which is%ld before D.
C format character: used to output one character
The number before C also indicates the width of the field, with D.
Char ch= ' a ';p rintf ("%c", ch);//Run output a
printf ("%5c", ch);//output a,a preceded by 4 spaces
Char c= '? '; printf ("%d%c", c,c);//output result 63?
3. s format character: used to output a string
printf ("%s", "China"); Export China
4. f Format character
1>%f
The integer part of the real number is all output, and the fractional part outputs 6 bits.
Double a=1.0; printf ("%f\n" A/3);//Run Result: 0.333333//Although a is double precision, A/3 is also double precision but%f format can only output 6 bits
2>%m.nf
Specify data width and scale, such as%7.2f for data 7 columns, where decimals is 2 bits
printf ("%20.15f\n", A/3); Output: 0.333333333333333,//with 3 spaces in front of 0
And a double precision can only guarantee the accuracy of 15 digits of valid digits. Float can only guarantee 6-bit
This article is from the "incomparable Warm yang" blog, please be sure to keep this source http://10797127.blog.51cto.com/10787127/1706108
Format character D C S F