The width specifier sets the minimum field width for an output value. Width is specified in one of two ways:
•
|
directly, through a decimal digit string;
|
•
|
indirectly, through an asterisk (*).
|
If you use an asterisk for the width specifier, the next argument in the call (which must be an int) specifies the minimum output field width.
Nonexistent or small field widths do cause truncation of a field. If the result of a conversion is wider than the field width, the field is expanded to contain the conversion result.
Width specifier
|
How output width is affected
|
n
|
At least n characters are printed. If the output value has less than n characters, the output is padded with blanks (right-padded if - flag given, left-padded otherwise).
|
0n
|
At least n characters are printed. If the output value has less than n characters, it is filled on the left with zeros.
|
*
|
The argument list supplies the width specifier, which must precede the actual argument being formatted.
|
|