格式化的IO功能(* printf / * scanf)中转换说明符%i和%d有什么区别 [英] What is the difference between conversion specifiers %i and %d in formatted IO functions (*printf / *scanf)
本文介绍了格式化的IO功能(* printf / * scanf)中转换说明符%i和%d有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
%d
和%i
在 printf
?
推荐答案
用于输出时,它们是相同的,例如与 printf
。
They are the same when used for output, e.g. with printf
.
但是,当用作输入说明符时,它们是不同的,例如使用 scanf
,其中%d
扫描整数作为带符号的十进制数,而%i
默认为十进制,但也允许十六进制(如果以 0x
开头)和八进制(如果以 0 $ c开头) $ c>)。
However, these are different when used as input specifier e.g. with scanf
, where %d
scans an integer as a signed decimal number, but %i
defaults to decimal but also allows hexadecimal (if preceded by 0x
) and octal (if preceded by 0
).
所以 033
将是27,其中%i
,但33个%d
。
So 033
would be 27 with %i
but 33 with %d
.
这篇关于格式化的IO功能(* printf / * scanf)中转换说明符%i和%d有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文