What are Input/Output Functions???
Input/Output Functions allows us to communicate with the user. Like Input Function allow us to take information from the user, and Output Function allows us to display that information which we collect from the User.
Input/Output Functions
We have printf() and scanf(), which are used to display output to the user and take input from the user, respectively. Let’s talk about both and understand it briefly how they works.
C Language E-Book
printf() Function
printf() – This function is used to display the output on the screen. It allows you to format and print various types of data, such as text and variables. Like if I want to print “Hello World” Then we write,
printf("Hello, World!\n");
scanf() Function
scanf() – This Function is used to take input from the user. Like if I want any number from the user Then I write,
scanf("%d", &num);
- ‘%d’ means we are expecting the Integer value and ‘&’ is used to indicate a address of the variable. Because scanf() wants address of the variables to take input.
Example: Input/output
Let’s take an example of input/output Functions to understand it briefly.
#include <stdio.h> int main() { int num; // Input printf("Enter a number: "); scanf("%d", &num); // Output printf("You entered: %d\n", num); return 0; }