The i
specification is for integers. Note that x
s are
included in the sample printf
statements to clarify the placement of
padding characters.
If you happen to want an integer printed in octal notation, use the
o
specification instead of i
. If you want hexadecimal, use
the x
specification instead of i
.
Display short or integer or long:
printf ("x %i x\n", 816); printf ("x %i x\n", -816); --- Result --- x 816 x x -816 x
Display with spaces, if necessary, to fill a six-character field:
printf ("x %6i x\n", 816); printf ("x %6i x\n", -816); --- Result --- x 816 x x -816 x
Display with spaces, if necessary, to fill a six-character field; if more than six characters are involved, display them all anyway:
printf ("x %6i x\n", 8160000); printf ("x %6i x\n", -8160000); --- Result --- x 8160000 x x -8160000 x
Display with spaces on the right, if necessary:
printf ("x %-6i x\n", 816); printf ("x %-6i x\n", -816); --- Result --- x 816 x x -816 x
Always include sign:
printf ("x %+6i x\n", 816); printf ("x %+6i x\n", -816); --- Result --- x +816 x x -816 x
Always include sign and pad on the right:
printf ("x %+-6i x\n", 816); printf ("x %+-6i x\n", -816); --- Result --- x +816 x x -816 x