You can specify a field width between% and d (for decimal). It represents the total number of characters printed. A positive value, as mentioned in another answer, aligns the output to the right and is the default value. A negative value aligns the text to the left. example:
int a = 3; printf("|%-3d|", a);
Exit:
|3 |
You can also specify the field width as an additional parameter using the * character:
int a = 3; printf("|%*d|", 5, a);
which gives:
| 3|
source share