(why_format_specifier_d_over_i)=
# Why do I prefer the format specifier `%d` over `%i` in `printf`?

You can also use `%i` for printing integer numbers, which may sound more intuitive, because it begins with *i*. Most C code uses `%d` however, because in `scanf`, `%d` and `%i` have a subtle difference. `%d` only reads decimal numbers, but `%i` can read other bases like octal and hexadecimal as well. So even `%i` and `%d` have the same meaning in `printf`, I would use `%d` for consistency between `scanf` and `printf` format strings.

:::{literalinclude} ../code/format_specifier_d_vs_i.c
:language: c
:::
:::{literalinclude} ../code/format_specifier_d_vs_i.txt
:language: text
:::

