• Home
  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React.js
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Brainstorm
STEMTrainingGrounds
  • Courses
    • Home
    • JavaScript
      • Introduction to JavaScript
      • JavaScript Developer
    • TypeScript
      • Introduction to TypeScript
      • TypeScript Developer
    • React
      • Introduction to React
      • React Developer
    • Python
      • Introduction to Python
      • Python Developer
    • C++
      • Introduction to C++
      • C++ Developer
    • C Language
      • Introduction to C
      • C Developer
    • Rust
      • Introduction to Rust
      • Rust Developer
    • Zig
      • Introduction to Zig
      • Zig Developer
    • Linux Shell
      • Introduction to the Linux Shell
      • Linux Shell Developer
  • Interactive Training
  • Pricing
  • Reading Grounds

Quick Links

  • About Us
  • Pricing
  • Partnership
  • Brainstorm
  • Terms
  • Privacy
  • Refunds
  • Featured on DanielLaunches

Courses

  • JavaScript
    • Introduction to JavaScript
    • JavaScript Developer
  • TypeScript
    • Introduction to TypeScript
    • TypeScript Developer
  • React
    • Introduction to React
    • React Developer
  • Python
    • Introduction to Python
    • Python Developer
  • C++
    • Introduction to C++
    • C++ Developer
  • C Language
    • Introduction to C
    • C Developer
  • Rust
    • Introduction to Rust
    • Rust Developer
  • Zig
    • Introduction to Zig
    • Zig Developer
  • Linux Shell
    • Introduction to the Linux Shell
    • Linux Shell Developer

Newsletter

Subscribe to our free monthly newsletter, for a quick update on Python, JavaScript, and React news

© 2025 - 2026 STEMTrainingGrounds. All Rights Reserved.

C Developer - Lesson 1

Lesson not found

printf

Lesson Progress: 0%

Lesson Progress: 0%
printf
Lesson Incomplete
Lesson not found

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.

Code Example
#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

Instructions

▼ ← Click the triangle to hide or reveal instructions.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • printf stands for "print formatted" and is found in the stdio.h header file.
  • Anything inside double quotes after printf is a format string that gets printed to the screen.
  • The \n inside the string is a newline character that moves the cursor to the next line after printing.
  • Every printf call must end with a semicolon, just like any other statement in C.
  • When you run the program, printf sends the text to a place called standard output, which is usually your terminal screen.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • Escape sequences start with a backslash \ 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.
  • You can use multiple escape sequences in a single format string to control the layout of your output.
  • Escape sequences are not printed as text — they are invisible commands that change where or how the next text appears.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • %d is the format specifier for integers (whole numbers) inside a printf format string.
  • After the format string, you list the values you want to print, separated by commas.
  • Each %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.
  • The number you pass to printf does not need to be stored in a variable first — you can write the number directly.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • %c is the format specifier for a single character.
  • Characters in C are written inside single quotes, like 'A' or '?'.
  • Each character you pass is a char value, and printf displays the exact symbol or letter.
  • You can print letters, digits, punctuation marks, and any other symbol that appears on your keyboard.
  • Using %c is the simplest way to display a single character on the screen.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • %f is the format specifier for floating-point numbers (numbers with a decimal point).
  • By default, %f shows six digits after the decimal point, even if they are zeros.
  • You can control how many digits appear after the decimal by placing a dot and a number between % and f, like %.2f for two decimal places.
  • A precision of %.1f shows one digit after the decimal, and %.0f shows none at all.
  • Precision control helps you format currency, measurements, or any value that needs a specific number of decimal places.
Code Example
#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.

C Code Editor

Task Incomplete

Editor Input:

Editor Output:

Click "Run Code" to see the output here
  • You can combine multiple format specifiers in one printf call to print different types of values together.
  • The values after the format string are matched in order: the first %d gets the first value, the %c gets the second, and so on.
  • Spaces and text inside the format string appear exactly as written, making it easy to create readable output.
  • Using one printf instead of several keeps your code shorter and easier to read.
  • Format specifiers, escape sequences, and plain text can all work together inside a single format string.

Test Incomplete

What does printf stand for in C?

Question #

1/15

Score

0/0 - 0.0 %