C Input and Output
What is C Input and Output?
In this tutorial, you are going to learn about C Input and Output. C Language provides mechanisms to take input from users and display their outputs. C Input refers to storing the value in the memory after its execution. C output in the other hand displays such values stored in memory. There are various built-in functions used in C which is used to perform the supplying input data to the program and obtaining the output results from the program.
In this tutorial, you will learn about different built-in functions which can be used for providing inputs from the user to the computer. They also support in displaying the outputs in the screen and their respective header files.
scanf() and printf() functions
scanf() and printf() functions definitions are contained by the header file stdio.h which is used for taking input from the user and displaying output on the screen respectively.
#include <stdio.h> int main(){ int a, b; printf("Enter values that you want to display"); scanf("%d", &a); printf("You entered: %d",a); }
The program above illustrates a simple program which takes input from the user and displays the output. The scanf() function takes an input from the user as per their type specified. On the other hand, the printf() function will print the parameters that are passed into the program in the console screen.
You might have been wondering about what is the purpose of using “%d” inside the printf() and scanf() functions. They are format specifiers. Format specifiers are used while giving input and displaying an output of the program. It is a mechanism to tell the compiler about what data are going to be used in the variables and the type of data to be printed. The table below lists some of the most used format specifiers in C with their respective uses.
%f | It is used for scanning and printing floating point number. |
%d | It is used for scanning and printing signed decimal number. |
%S | It is used for scanning and printing character string. |
%c | It is used for scanning and printing a character. |