Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个变量:
int a = 0x0304;
我这样打印出来:
printf("the value is 0x4x\n", a);
但它显示值是0x304,我想要的结果应该是值0x0304,如何像这样打印出来?
0x304,
0x0304
0尝试在格式说明符中添加前导-%04x
0
%04x
printf("the value is 0x%04x\n", a);
以防万一您的问题中遗漏的不是错字,请注意我还添加了 a%以使其成为格式说明符。就目前而言,您问题中的代码会得到回应the value is 0x4x
%
the value is 0x4x