printf() 中的井号“#"有什么作用? [英] What does a hash sign '#' do in printf()?
本文介绍了printf() 中的井号“#"有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int x = 0xff;
printf("%#x",x);
输出:0xff
printf("%x",x);
输出:ff
为什么输出有差异?#
具体是做什么的?
Why is there a difference in output? What does #
specifically do?
推荐答案
标准说:
7.21.6 - 2
结果被转换为替代形式".... 对于 x(或 X)转换,非零结果带有 0x(或 0X)前缀.
The result is converted to an ‘‘alternative form’’. ... For x (or X) conversion, a nonzero result has 0x (or 0X) prefixed to it.
它还有其他有趣的东西(尤其是花车),但我很少看到它被使用——老实说,我不得不查阅它才能记住.
It does other interesting stuff (especially for floats) but I have rarely seen it used - I honestly admit I had to look it up to remember.
这篇关于printf() 中的井号“#"有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文