Skip to main content

printf

A format specifier follows this prototype:

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

Where the specifier character at the end is the most significant component, since it defines the type and the interpretation of its corresponding argument:

specifierOutputExample
d or iSigned decimal integer392
uUnsigned decimal integer7235
oUnsigned octal610
xUnsigned hexadecimal integer7fa
XUnsigned hexadecimal integer (uppercase)7FA
fDecimal floating point, lowercase392.65
FDecimal floating point, uppercase392.65
eScientific notation (mantissa/exponent), lowercase3.9265e+2
EScientific notation (mantissa/exponent), uppercase3.9265E+2
gUse the shortest representation: %e or %f392.65
GUse the shortest representation: %E or %F392.65
aHexadecimal floating point, lowercase-0xc.90fep-2
AHexadecimal floating point, uppercase-0XC.90FEP-2
cCharactera
sString of characterssample
pPointer addressb8000000
nNothing 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.%

Return Value

On success, the total number of characters written is returned.

If a writing error occurs, theerror indicator(ferror) is set and a negative number is returned.

If a multibyte character encoding error occurs while writing wide characters, errno is set toEILSEQand a negative number is returned.

Reference

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