Understanding Printf() and Scanf().

What is printf?

Meaning:

printf means “print formatted” — it shows messages or numbers on the screen.

Think of it like:

Telling the computer:
“Say this out loud on the screen.”

Example:

printf("Hello!");

The computer will show:

Hello!

You can also print numbers:

int age = 10;
printf("I am %d years old", age);

Here:

  • %d is a placeholder for a number.
  • age is the number to show.

Output:

I am 10 years old

What is scanf?

Meaning:

scanf means “scan formatted” — it reads what the user types on the keyboard.

Think of it like:

Telling the computer:
“Listen to the user and save what they type.”

Example:

int age;
scanf("%d", &age);
  • %d means: “I’m reading a number.”
  • &age means: “Put that number inside the age box.”

Simple Program Using Both

#include <stdio.h>

int main() {
int age;

printf("Enter your age: ");
scanf("%d", &age);

printf("You are %d years old!", age);

return 0;
}

What Happens:

  1. printf() shows: Enter your age:
  2. User types: 15
  3. scanf() reads it and puts it into age.
  4. printf() then shows: You are 15 years old!

Leave a Comment