What is the difference between conversion specifiers %i and %d in formatted IO functions (*printf / *scanf)
在
当用于输出时它们是相同的,例如与
但是,当用作输入说明符时,它们是不同的。使用
所以
对于
The conversion specifiers and their meanings are:
并包括以下项目符号:
1
2
3
4
5
6 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. The default precision is
1. The result of converting a zero value with a precision of zero is
no characters.
另一方面,对于
The conversion specifiers and their meanings are:
并包括以下内容:
1
2
3
4
5
6
7
8
9 d Matches an optionally signed decimal integer, whose format is the
same as expected for the subject sequence of the strtol function with
the value 10 for the base argument. The corresponding argument shall
be a pointer to signed integer.
i Matches an optionally signed integer, whose format is the same as
expected for the subject sequence of the strtol function with the
value 0 for the base argument. The corresponding argument shall be a
pointer to signed integer.