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

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

最佳回答

独特的樱桃

苹果冬瓜

2026-04-08 03:06:57

加号"+"表示强制显示正负号(+和-)。默认是右对齐,想要左对齐就用减号"-"。
参考:
- 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-04-08 03:06:57

    加号"+"表示强制显示正负号(+和-)。默认是右对齐,想要左对齐就用减号"-"。参考:- 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的区别

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