As others said, they produce identical output on printf, but behave differently on scanf. I would prefer %d
over %i
for this reason. A number that is printed with %d
can be read in with %d
and you will get the same number. That is not always true with %i
, if you ever choose to use zero padding. Because it is common to copy printf format strings into scanf format strings, I would avoid %i
, since it could give you a surprising bug introduction:
I write fprintf("%i ...", ...);
You copy and write fscanf(%i ...", ...);
I decide I want to align columns more nicely and make alphabetization behave the same as sorting: fprintf("%03i ...", ...);
(or %04d
)
Now when you read my numbers, anything between 10 and 99 is interpreted in octal. Oops.
If you want decimal formatting, just say so.