Should I use %i or %d to print an integer in C using printf()?

They are completely equivalent when used with printf(). Personally, I prefer %d. It’s used more often (should I say “it’s the idiomatic conversion specifier for int“?).

(One difference between %i and %d is that when used with scanf(), then %d always expects a decimal integer, whereas %i recognizes the 0 and 0x prefixes as octal and hexadecimal, but no sane programmer uses scanf() anyway, so this should not be a concern.)

Leave a Comment