Ayo*_* M. 193 c c++ printf scanf format-specifiers
%d和%i用作格式说明符的区别是什么printf?
Dip*_*ick 265
当用于输出时它们是相同的,例如printf.
但是,当用作输入说明符时,这些是不同的,例如scanf,其中,%d将整数扫描为带符号的十进制数,但%i默认为十进制,但也允许十六进制(如果前面加上0x)和八进制(如果前面加上)0.
所以03327 %i岁,但33岁%d.
jas*_*son 67
这些是相同的printf但不同的scanf.for printf,both %d和%i指定带符号的十进制整数.为scanf,%d并且%i也意味着带符号的整数,但%i如果前面由inteprets输入为十六进制数0x和八进制如果前面由0否则解释输入为十进制.
Sha*_*our 20
%i和%d格式说明符之间没有区别printf.我们可以通过参考草案C99标准部分来看到这一点7.19.6.1 .fprintf函数也涉及printf格式说明符,它在第8段中说:
转换说明符及其含义是:
并包括以下项目:
Run Code Online (Sandbox Code Playgroud)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.
另一方面,由于scanf存在差异,%d假设基数为10而%i自动检测基数.我们可以通过将部分看到这个7.19.6.2 fscanf函数覆盖scanf相对于格式说明,在第12这样说的:
转换说明符及其含义是:
并包括以下内容:
Run Code Online (Sandbox Code Playgroud)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.
| 归档时间: | 
 | 
| 查看次数: | 127904 次 | 
| 最近记录: |