Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What is the difference between -8 1d, %-08 1d,% 08 1d and %+08 1d in C language?
What is the difference between -8 1d, %-08 1d,% 08 1d and %+08 1d in C language?
1. Character width modifier (number)

If the data width is not enough, it will be filled with spaces on the left by default, and it will be automatically expanded if it exceeds the set width.

2."0"? adjunct

Use zero as padding

3. "-"modifier

Data items are aligned to the left in the range, and data items are output from the leftmost position of the range.

4."+"

Output another plus sign.

Note: When "0" and width modifier are added after "-"is modified, zero will not be added to the right side of the data (the "0" modifier will be invalid at this time).

To sum up, there are generally two usages:

printf("%-8ld\n ",num);

printf("%08ld\n ",num);

As shown in the figure below: