Flags

Flags can be zero or more (in any order) of:

a number

Causes printf to left-pad the output with spaces until the required length of output is attained. If combined with '0' (see below), it will cause the sign to become a space when positive, but the remaining characters will be zero-padded

+

Causes printf to always denote the sign '+' or '-' of a number (the default is to omit the sign for positive numbers). Only applicable to numeric types.

-

Causes printf to left-align the output of this placeholder (the default is to right-align the output).

#

Alternate form. For 'g' and 'G', trailing zeros are not removed. For 'f', 'F', 'e', 'E', 'g', 'G', the output always contains a decimal point. For 'o', 'x', and 'X', a 0, 0x, and 0X, respectively, is prepended to non-zero numbers.

0

Causes printf to use 0 instead of spaces to left-fill a fixed-length field. For example, printf("%2d", 3) results in " 3", while printf("%02d", 3) results in "03".