问题
int x = 0xff;
printf("%#x",x);
Output: 0xff
printf("%x",x);
Ouput: ff
Why is there a difference in output? What does #
specifically do?
回答1:
The standard says:
7.21.6 - 2
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.
来源:https://stackoverflow.com/questions/11922876/what-does-a-hash-sign-do-in-printf