Notes / C / Input & Output

Input & Output in C — Revision Notes

A quick-reference cheat sheet: definition, syntax, example, common mistakes and an interview tip.

beginner 📖 2 min revision

Definition

📌 Input & Output C uses two core functions for console I/O: printf() to print output, and scanf() to read input from the keyboard.

Syntax

syntax
printf("format string", values...);
scanf("format string", &variable);

Example

c
#include <stdio.h>

int main() {
    int age;
    printf("Enter your age: ");
    scanf("%d", &age);
    printf("You are %d years old.\n", age);
    return 0;
}

Output

outputEnter your age: 20 You are 20 years old.

Important Points

Common Mistakes

Interview Tip

🎯 Before your interview Be ready to explain why scanf needs a pointer (&variable): it has to modify the variable's actual memory, not a copy of its value.
Back to notes Read full lesson →