I’ve just spotted the following in the C99 ISO standard, 7.19.6.1 The fprintf function, subsection 6, detailing the conversion flags, specifically the 0 flag:
0: d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros (following any indication of sign or base) are used to pad to the field width rather than performing space padding, except when converting an infinity or NaN.
So far so good, I know that the following lines will produce the shown output:
printf ("%5d\n", 7); // produces " 7"
printf ("%05d\n",7); // produces "00007"
However, in subsection 8 detailing the conversion modifiers, I see:
d,i: The int argument is converted to signed decimal in the style [−]dddd. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer digits, it is expanded with leading zeros.
That’s plainly not the case since the default behaviour is to pad with spaces, not zeroes. Or am I misreading something here?
You’re confusing precision and field width: