Input/Output - Like Talking to the Computer
Think of Input/Output (I/O) in C as your way of talking to the computer. You tell the computer what you want to do, and it shows you the results.
Simple I/O in C:
Printing Something (Output):
When you want the computer to show something, you use printf(). It's like telling the computer, "Hey, display this on the screen."
#include <stdio.h>
int main()
{
printf("Hello, Computer!\n");
return 0; // Indicates successful execution
}
output:Hello, Computer!
Here, printf("Hello, Computer!\n"); tells the computer to print "Hello, Computer!" on the screen.
Taking Something (Input):
When you want the computer to listen and remember something you say, you use scanf(). It's like saying, "Hey, computer, I'm going to tell you something, and you should remember it."
#include <stdio.h>
int main()
{
int age;
printf("How old are you? ");
scanf("%d", &age);
printf("You are %d years old!\n", age);
return 0; // Indicates successful execution
}
output:
How old are you? (you type 25)
You are 25 years old!
Here, scanf("%d", &age); listens for a number you type, and printf("You are %d years old!\n", age); shows it back to you.
Why Input/Output Matters:
I/O is like the conversation between you and the computer. It allows you to give instructions and get results.
It makes your programs interactive. You can ask questions and get responses.
So, printing with printf is like the computer talking to you, and scanning with scanf is like you talking to the computer. It's the language you use to communicate with your electronic friend!
0 Comments
If you have any doubts, Please let me know