Lesson not found
Lesson Progress: 0%
printfis one of the most important functions in C. It lets you display text, numbers, and other values on the screen. The name stands for "print formatted" because you control exactly how the output looks. You give printf a format string that describes what to print, and then you provide the values you want to display. Special markers inside the format string called format specifiers tell printf where to insert each value and what type it is. Learning printf is essential because almost every C program uses it to show results, debug information, or messages to the user. Once you master printf, you can make your programs communicate clearly with anyone who runs them.
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
printf stands for "print formatted" and is found in the stdio.h header file.printf is a format string that gets printed to the screen.\n inside the string is a newline character that moves the cursor to the next line after printing.printf call must end with a semicolon, just like any other statement in C.printf sends the text to a place called standard output, which is usually your terminal screen.#include <stdio.h>
int main() {
printf("First\nSecond\n");
printf("A\tB\tC\n");
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
\ and give special meaning to the character that follows.\n moves the cursor to the beginning of the next line, like pressing Enter.\t moves the cursor to the next tab stop, helping you align text into columns.#include <stdio.h>
int main() {
printf("%d\n", 42);
printf("%d\n", -10);
printf("%d\n", 256);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
%d is the format specifier for integers (whole numbers) inside a printf format string.%d in the format string is replaced by the corresponding value in order.printf can print positive numbers, negative numbers, and even zero without any extra work.printf does not need to be stored in a variable first — you can write the number directly.#include <stdio.h>
int main() {
printf("%c\n", 'A');
printf("%c\n", 'Z');
printf("%c\n", '?');
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
%c is the format specifier for a single character.'A' or '?'.char value, and printf displays the exact symbol or letter.%c is the simplest way to display a single character on the screen.#include <stdio.h>
int main() {
printf("%f\n", 3.14);
printf("%.1f\n", 3.14);
printf("%.2f\n", 3.14);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
%f is the format specifier for floating-point numbers (numbers with a decimal point).%f shows six digits after the decimal point, even if they are zeros.% and f, like %.2f for two decimal places.%.1f shows one digit after the decimal, and %.0f shows none at all.#include <stdio.h>
int main() {
printf("%d %c %f\n", 65, 'A', 1.5);
return 0;
}Instructions
▼ ← Click the triangle to hide or reveal instructions.Task Incomplete
Editor Input:
Editor Output:
printf call to print different types of values together.%d gets the first value, the %c gets the second, and so on.printf instead of several keeps your code shorter and easier to read.Test Incomplete