printf Format Specifiers
Print values precisely.
printf Format Specifiers is a free C Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the C Academy learning path, and your progress syncs across the web and the CoddyKit app. The C Academy course includes 4 lessons in total.
What printf Does
printf writes formatted text to the screen. Format specifiers starting with % are replaced by your values.
#include <stdio.h>
int main(void) {
printf("Hello, world!\n");
return 0;
}Printing Integers with %d
Use %d for a signed decimal integer.
#include <stdio.h>
int main(void) {
int age = 30;
printf("Age: %d\n", age);
return 0;
}Printing Floats with %f
Use %f for floating-point values. By default it prints six decimals.
#include <stdio.h>
int main(void) {
double price = 9.5;
printf("Price: %f\n", price);
return 0;
}Printing Characters with %c
Use %c to print a single character.
#include <stdio.h>
int main(void) {
char grade = 'A';
printf("Grade: %c\n", grade);
return 0;
}Printing Strings with %s
Use %s to print a C string (a char array).
#include <stdio.h>
int main(void) {
char name[] = "Alice";
printf("Name: %s\n", name);
return 0;
}Multiple Values
One printf can hold several specifiers; supply the arguments in the same order.
#include <stdio.h>
int main(void) {
char name[] = "Bob";
int age = 25;
printf("%s is %d years old\n", name, age);
return 0;
}Printing a Literal Percent
To print an actual % sign, write %%.
#include <stdio.h>
int main(void) {
int pct = 80;
printf("Battery: %d%%\n", pct);
return 0;
}Hexadecimal and Octal
%x prints in hexadecimal and %o in octal.
#include <stdio.h>
int main(void) {
int n = 255;
printf("hex: %x oct: %o\n", n, n);
return 0;
}Long and Unsigned
Use %ld for long and %u for unsigned int to match the argument type.
#include <stdio.h>
int main(void) {
long big = 1000000L;
unsigned int u = 4000000000u;
printf("%ld %u\n", big, u);
return 0;
}Matching Type to Specifier
The specifier must match the argument type. A mismatch like printing a double with %d is undefined behavior.
#include <stdio.h>
int main(void) {
double d = 3.5;
printf("%f\n", d);
return 0;
}Newlines and Tabs
Escape sequences like \n and \t control layout inside the format string.
#include <stdio.h>
int main(void) {
printf("Col1\tCol2\n");
printf("a\tb\n");
return 0;
}Quick Check
Test your understanding of printf specifiers.
Recap: printf Format Specifiers
You learned how printf formats output.
%dintegers,%ffloats,%cchars,%sstrings%xhex,%ooctal,%uunsigned,%ldlong%%prints a literal percent- Specifier must match argument type
- Escape sequences control layout
Learn C with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 39
- Lessons
- 144
Frequently Asked Questions
Is the “printf Format Specifiers” lesson free?
Yes — the full text of “printf Format Specifiers” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the C Academy course, upgrade to CoddyKit PRO. The C Academy course includes 4 lessons in total.
What will I learn in “printf Format Specifiers”?
Print values precisely. You practise C Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start C Academy?
No prior experience is required. C Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.
How long does the “printf Format Specifiers” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this C Academy lesson?
Yes. Every C Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- printf Format Specifiers
- scanf and Input
- Width, Precision, Flags
- Common I/O Pitfalls