<p>I'm trying to find a good way to print leading <code>0</code>, such as <code>01001</code> for a <a href="https://en.wikipedia.org/wiki/ZIP_Code" rel="noreferrer">ZIP Code</a>. While the number would be stored as <code>1001</code>, what is a good way to do it?</p>
<p>I thought of using either <code>case</code> statements or <code>if</code> to figure out how many digits the number is and then convert it to an <code>char</code> array with extra <code>0</code>'s for printing, but I can't help but think there may be a way to do this with the <code>printf</code> format syntax that is eluding me.</p>

```
```
printf("%05d", zipCode);
```
```
The
```
0
```
indicates what you are padding with and the
```
5
```
shows the width of the integer number.
Example 1: If you use
```
"%02d"
```
(useful for dates) this would only pad zeros for numbers in the ones column. E.g.,
```
06
```
instead of
```
6
```
.
Example 2:
```
"%03d"
```
would pad 2 zeros for one number in the ones column and pad 1 zero for a number in the tens column. E.g., number 7 padded to
```
007
```
and number 17 padded to
```
017
```
.