int y=1234;printf(“y=%+06d\n”),结果为什么是y=+01234?

学习 时间:2026-08-16 07:24:12 阅读:9021
int y=1234;printf(“y=%+06d\n”),结果为什么是y=+01234?+表示 右对齐;0表示 补零;6 表示 占6个长度;为什么还有个+ 号 ?、

最佳回答

靓丽的咖啡

霸气的苗条

2026-08-16 07:24:12

加号"+"表示强制显示正负号(+和-)。默认是右对齐,想要左对齐就用减号"-"。
参考:
- Left-justify within the given field width; Right justification is the default (see width sub-specifier)。
+ Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers。 By default, only negative numbers are preceded with a - sign。

最新回答共有2条回答

  • 爱笑的巨人
    回复
    2026-08-16 07:24:12

    加号"+"表示强制显示正负号(+和-)。默认是右对齐,想要左对齐就用减号"-"。参考:- Left-justify within the given field width; Right justification is the default (see width sub-specifier)。 + Forces to precede the result with a plus or minus sign (+ or -) even for positive numbers。 By default, only negative numbers are preceded with a - sign。

上一篇 going to the movies和 go to the movies的区别

下一篇 吸尘器能代替拖把吗