格式说明符%i和%d在printf的区别 [英] Difference between format specifiers %i and %d in printf

查看:200
本文介绍了格式说明符%i和%d在printf的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是%d个%I 的格式说明在使用时的printf ?

What is the difference between %d and %i when used as format specifiers in printf?

推荐答案

它们是相同用于输出时,例如与的printf

They are the same when used for output, e.g. with printf.

然而,这些输入说明例如使用时是不同的与 scanf函数,其中%d个扫描一个整数作为符号十进制数,但%I 默认为小数,但也允许十六进制(如$ p $由 0X pceded)和八进制如果$ p $由 pceded 0

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.

这篇关于格式说明符%i和%d在printf的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆