Loading lessons...
C Cheatsheet: Specifiers
Cheatsheet: printf Specifiers
The order-matter pair in C.
| Specifier | Type |
|---|---|
| %d | int |
| %ld | long int |
| %f | float / double (print) |
| %c | char |
| %s | string (char[]) |
| %p | pointer |
| %.2f | float with 2 decimals |
| %e | scientific 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.