printf——格式化输出说明

printf格式说明符遵循以下原则:

%[flags][width][.precision][length]specifier

%[标志][宽度][.精度][长度]说明符

specifier Output Example
d or i 带符号的十进制整数 392
u 无符号的十进制整数 7235
o 无符号八进制数字 610
x 无符号十六进制整数 7fa
X 无符号十六进制整型(大写) 7FA
f 十进制浮点数,小写 392.65
F 十进制浮点数,大写 392.65
e Scientific notation (mantissa/exponent), lowercase 3.9265e+2
E Scientific notation (mantissa/exponent), uppercase 3.9265E+2
g Use the shortest representation: %e or %f 392.65
G Use the shortest representation: %E or %F 392.65
a Hexadecimal floating point, lowercase -0xc.90fep-2
A Hexadecimal floating point, uppercase -0XC.90FEP-2
c 字符 a
s 字符串 sample
p 指针地址 b8000000
n Nothing printed.
The corresponding argument must be a pointer to a signed int.
The number of characters written so far is stored in the pointed location.
% A % followed by another % character will write a single % to the stream. %

http://www.cplusplus.com/reference/cstdio/printf/