HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to CVariablesData TypesOperatorsStringsArraysConditions (if / switch)Loops (for / while)FunctionsPointers
REFERENCE
📖 Overview
🖥️ Output & Input
printf()Format specifiers (%d %f %c %s)scanf()
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array
🔁 Condition & Loop
🧩 Function
👉 Pointer
C›REFERENCE›Output & Input
🖥️

Output & Input

Formatted printing with printf and reading with scanf.

CommandDescription
printf()Writes formatted output.
Format specifiers (%d %f %c %s)Placeholder according to value type.
scanf()Reads input from the user.

printf()

Try it yourself →

Writes formatted output.

Syntax

printf("format", ...)

Description

Writes with placeholders: %d integer, %f float, %c character, %s text. Add \n for a new line.

Example

#include <stdio.h>
int main() {
    printf("Number: %d\n", 42);
    printf("Text: %s\n", "Alex");
    return 0;
}

Expected output

Number: 42
Text: Alex

When to use?

Showing results, debugging.

Common mistakes

  • ⚠️ New lines are not automatic; don't forget to add \n.
  • ⚠️ Printing text with %d or numbers with %s is undefined behavior.

Format specifiers (%d %f %c %s)

Try it yourself →

Placeholder according to value type.

Syntax

%d %f %c %s %x

Description

%d integer, %f float, %c single character, %s text, %x hexadecimal. %.2f for 2 decimal places.

Example

#include <stdio.h>
int main() {
    printf("%c %d %.2f\n", 'A', 65, 3.14159);
    return 0;
}

Expected output

A 65 3.14

When to use?

Formatted output.

scanf()

Try it yourself →

Reads input from the user.

Syntax

scanf("%d", &variable)

Description

Reads from the keyboard. The ADDRESS (&) of the variable is provided. & is not needed for string arrays.

Example

#include <stdio.h>
int main() {
    int x;
    scanf("%d", &x);
    printf("You entered: %d\n", x);
    return 0;
}

Expected output

(depending on the entered number) You entered: 5

When to use?

Console input.

Common mistakes

  • ⚠️ Forgetting the & sign causes a crash: scanf("%d", &x).
HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code