Skip to content

C conversion specifiers and modifiers

A handy reference to C conversion specifiers and modifiers

In this post I want to create a helpful reference for all the C conversion specifiers you can use, commonly with printf(), scanf() and similar I/O functions.

SpecifierMeaning
%d / %iSigned decimal integer
%uUnsigned decimal integer
%cUnsigned char
%sString
%pPointer in hexadecimal form
%oUnsigned octal integer
%x / %XUnsigned hexadecimal number
%eFloating point number in exponential format in e notation
%EFloating point number in exponential format in E notation
%fdouble number in decimal format
%g / %Gdouble number in decimal format or exponential format depending on the value

In addition to those specifiers, we have a set of modifiers.

Let’s start with digits. Using a digit between % and the format specifier, you can tell the minimum field width. Example: %3d will take 3 spaces regardless of the number printed.

This:

printf("%4d\n", 1);
printf("%4d\n", 12);
printf("%4d\n", 123);
printf("%4d\n", 1234);

should print

   1
  12
 123
1234

If you put a dot before the digit, you are not telling the precision: the number of decimal digits. This of course applies to decimal numbers. Example:

printf("%4.2f\n", 1.0);
printf("%4.3e\n", 12.232432442);
printf("%4.1e\n", 12.232432442);
printf("%4.1f\n", 123.22);

will print:

1.00
1.223e+01
1.2e+01
123.2

In addition to digits, we have 3 special letters: h, l and L.


→ Get my C Handbook

→ I wrote 17 books to help you become a better developer:

  • C Handbook
  • Command Line Handbook
  • CSS Handbook
  • Express Handbook
  • Git Cheat Sheet
  • Go Handbook
  • HTML Handbook
  • JS Handbook
  • Laravel Handbook
  • Next.js Handbook
  • Node.js Handbook
  • PHP Handbook
  • Python Handbook
  • React Handbook
  • SQL Handbook
  • Svelte Handbook
  • Swift Handbook
...download them all now!

Also, JOIN MY CODING BOOTCAMP, an amazing cohort course that will be a huge step up in your coding career - covering React, Next.js - next edition February 2025

Bootcamp 2025

Join the waiting list