Input and Output Statements in C

In our earlier post we introduced you to C language.Today we shall learn about input and output statements in C.These statements are used for intake of data from the user and display the output after processing to the user.

First we shall learn about the output statements present in C language.The main and important output statement present in C is “printf”.This is a keyword and we include the stdio.h header file in our program.The syntax of the printf statement is as follows:


In the place of dashed line you can place your message for the user.There are other types of input statements in C as substitute for “printf” statement.The other output statements are:
1. puts().
2. putchar().
1.When we need to display strings then we use puts() function to display.
2.When we need to display character by character then we use putchar() method to display.

Let us write a program to demonstrate the use of printf().

void main()
  printf("Welcome to the world of Programmming");

Welcome to the world of Programming
So….we have learnt how to display our message to the user.Let us go to the next part of our today’s tutorial….i.e about input statements.
The main and most important input statement used in C programming is “scanf()” statement.The syntatx of the “scanf()” statement is:


In the above syntax…… in the place of ** we need to enter a suitable format specifier.Format specifier is different for each of the datatype present in C. —- %d
2.char —- %c
3.string —- %s
4.Float —- %f.
These are format specifier and we need to remember them till the extinct of C language. Let us consider that a user is giving a number is input and we are going to store it a variable(named as num).Then the scanf() statement is as follows:
This is how we write a scanf() statement.The other types of input statements are:

These functions work similar to puts() and putchar().

Write a C Program such that we take a number as an input from the user and display the same number to him.

void main()
  int num;  //declaration of a variable
  printf("Please enter any number:") // using printf() to display the message
  scanf("%d",&num); // using scanf() statement and format specifiers
  printf("Given number by the user is:%d",num);

In the last printf() statement we again used format specifier to display the number present in the variable num……..From this we can say that we can use format specifiers in both printf() and scanf() statements.

Please enter any number:6
Given number by the user is:6
So,this is the end of today’s tutorial and next tutorial we shall learn about data types.


About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my Master's in Computer Science.
This entry was posted in C and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s