为什么printf(“**% d**",-31);
结果是**-31**
而不是** -31**
而printf(“**% d**",31);
结果就是** 31**
(为什么上面打印出来没有空格,而下面的打印出来就有空格)
% d
中的空格表示,如果输出结果没有符号,则在前面加一个空格
https://en.cppreference.com/w/c/io/fprintf
space: if the result of a signed conversion does not start with a sign character, or is empty, space is prepended to the result. It is ignored if + flag is present.
%d中间加空格,给整数保留了一个正负号的位置,加号一般省略,所以是空的
有没有可能是负号占的空间大呢
正数不显示+, 保留空格, 负数显示-
MSDN有说明的
sprintf 函数进format的详细说明
Flag Characters
blank (' ') Prefix the output value with a blank if the output value is signed and positive; the blank is ignored if both the blank and + flags appear.