Lesson 118 +10 XP

C Cheatsheet: Specifiers

Cheatsheet: printf Specifiers

The order-matter pair in C.

SpecifierType
%dint
%ldlong int
%ffloat / double (print)
%cchar
%sstring (char[])
%ppointer
%.2ffloat with 2 decimals
%escientific notation

Example

printf("%d and %.2f\n", 10, 3.14159);
// 10 and 3.14

Scanf hints

scanf needs a pointer, so write.

TL;DR

  • Match the specifier to the type exactly.
  • %.2f = two decimals.
  • scanf requires & to write into a variable.