Input Output Statement in C Programming

Welcome Folks, in this particular module we are going to discuss the Input Output Statement in C Programming, till now we have seen a lot in this C Programming series, and also in the last module we constructed a basic structure of the C program, also in this post we will move one step higher and step towards the more practical approach.

So, gear up with your energies, and let’s move into the depth of this module (Input Output Statement in C Programming).

Input Output Statement in C Programming

Input Output Statement in C Programming

Input Output Statement in C Programming simply means to give some data or information to the computer so that it can perform various types of actions and produce the desired result, and this result is termed output. Recall the previous module Hello World Program in C, in that the program was simply printing Hello World on the screen without taking any input from the user, so in that Hello World was the output.

Now suppose you make coffee, in that you give milk, coffee powder, and sugar, for 5 minutes in a gas stove, so all these are the inputs and the output is your coffee ready. Simply if you want to perform any action in life that you have to produce some input from your side then only you will get the desired output.

scanf() and printf() are the two functions that help in taking input from the user and producing the desired result as output respectively. scanf sends the formatted input to the respective variable and stores it there, whereas printf sends the formatted output statement to the screen.

Let’s see some example code to get a clearer idea:

Input Output Statement in C Programming

#include <stdio.h>
int main()
    printf("Welcome to the");
    return 0;

The output of the above program:

Welcome to the

How does the above Input Output Statement in C Programming work?

We have written a simple program that just simply prints the given sentence as the output. Let’s see the working of the above Input Output Statement in C Programming.

  • We know that the execution of all valid C programs starts from the main function. Therefore, the program must contain the main function.
  • printf() is the function that gives the output on the screen, so in this program, it simply prints the string or sentence inside double quotations.
  • To use this printf() function, we need to include stdio.h header file, as it stands from the standard input-output library.
  • return 0; statement indicates the exit status of the program and also tells that the program is executed successfully, it’s optional as if you are using int main() then you have to give return 0 at the last, and if you are using void main() then you don’t have to use return 0 statement.

Let’s take another example in Input Output Statement in C Programming:

In this example, we will be using the scanf() function which will take the integer as input from the user and will print the same integer as output with the help of printf() function.

#include <stdio.h>
int main()
    int num ;
    printf("Enter the Integer: ") ;
    scanf(“%d”, &num) ;
    printf(“The Entered Integer is: %d”, num );
    return 0 ;

The output of the above program:

Enter the Integer: 30
The Entered Integer is: 30

In the above program, we are asking the user to enter an integer, and then the user will enter the integer that integer will be stored in the variable num, after that will print the same integer that the user integer.

You all must be wondering it is a little complicated program as we have used many different declarations but that declaration stands for data types and variables which we will be seeing in the next module, as far now you should know the use of scanf() and printf() function and their working.

In the above examples, you all must have noticed one thing and i.e., “%d, %f, %c” and all. So what is this and why we have used this…

Now comes the concept of Format Specifier.

Format Specifier in C Programming

These are all the format specifiers (%d, %f, etc.). The format specifiers are used in Input Output Statements in C Programming for performing different input and output operations. Using this concept the compiler can understand what type of data i.e., integer, character, string, decimal numbers, etc., is in a variable during taking input using the scanf() function and printing using printf() function.

Let’s see the list of Format specifiers available with can help you in Input Output Statement in C Programming:

Format Specifier Type
%c Character
%d Signed integer
%e or %E Scientific notation of floats
%f Float values
%g or %G Similar to %e or %E
%hi Signed integer (short)
%hu Unsigned Integer (short)
%i Unsigned integer
%l or %ld or %li Long
%lf Double
%Lf Long double
%lu Unsigned int or unsigned long
%lli or %lld Long long
%llu Unsigned long long
%o Octal representation
%p Pointer
%s String
%u Unsigned int
%x or %X Hexadecimal representation
%n Prints nothing
%% Prints % character

These are the list of format specifiers available in C, which are used with different data types and will see them more in the upcoming modules.

Hope you all are really excited about the next modules and learned a lot from this one (Input Output Statement in C programming). Stay connected.

Until then, Enjoy Coding and Happy Learning!