Kelvin
asked

Expert
Abhilekh Gautam answered
In C, scanf() is used to read input from the user, while printf() is used to display output on the screen.
Think of it this way:
scanf()receives data (input)printf()sends data to the screen (output)
Example:
#include <stdio.h>
int main() {
int age;
printf("Enter your age: "); // Output
scanf("%d", &age); // Input
printf("You are %d years old.", age); // Output
return 0;
}Here, printf() first prompts the user, and then scanf() captures the input into the age variable. After that, printf() is used again to show the result.
C
This question was asked as part of the Learn C Programming course.
Our Experts
Sanjeev PanditPrincipal Engineer
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Anuj ShresthaTech Lead
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer