C printf Formatters — Quick Reference

A single-page cheat sheet showing the common format specifiers, length modifiers, flags, width/precision, and examples for printf() in C and C++. (Now includes an interactive simulator!)

Reference Table

SpecifierMeaningExample
%d / %iSigned decimal integerprintf("%d", 42);
%uUnsigned decimal integerprintf("%u", 42);
%oUnsigned octalprintf("%o", 42);
%x / %XUnsigned hexadecimal (lower/upper)printf("%x", 42);
%f / %FDecimal floating pointprintf("%.2f", 3.14);
%e / %EScientific notationprintf("%e", 3.14);
%g / %GShortest of %e or %fprintf("%g", 3.14);
%a / %AHexadecimal floating pointprintf("%a", 3.14);
%cCharacterprintf("%c", 'A');
%sStringprintf("%s", "Hello");
%pPointerprintf("%p", ptr);
%nNumber of characters so far (writes to int*)printf("%n", &x);
%%Literal percent signprintf("%%");

Interactive "What does this print?" Simulator

Output will appear here