Startertutorials Blog
Tutorials and articles related to programming, computer science, technology and others.
Subscribe to Startertutorials.com's YouTube channel for different tutorial and lecture videos.

Categories: C Programming. No Comments on Input and Output in C Programming
0
(0)

In this article we will learn about input and output in C programming language. You will learn how to read data from keyboard and how to print text on to the console in C programming.

 

Reading Input from Keyboard

 

Another way of assigning values to variables besides directly assigning the value is reading values from the keyboard.

 

C provides scanf function in the stdio.h header file. Using this function we can read values from the keyboard and assign the values to variables. The syntax of scanf function is as shown below:

 

scanf-syntax


Subscribe to our monthly newsletter. Get notified about latest articles, offers and contests.


 

The control string specifies the type of value to read from the keyboard and the ampersand symbol & is an operator to specify the address the variable(s). Example usage of scanf function is shown below:

 

scanf-example

 

Printing onto Screen

 

To print or output text onto the screen, we use printf function. Syntax of printf function is as shown below:

 

printf-syntax

 

Example usage of printf function is shown below:

 

printf-example1

 

 

Following are the format specifiers or control strings available in C:

 

Data Type Format Specifier
int %d (or) %i
unsigned int %u
short int %hd
unsigned short int %hu
long int %ld
unsigned long int %lu
float %f (or) %e (or) %g
double %lf (or) %e (or) %g
long double %Lf
char %c
unsigned char %c
string %s

 

How useful was this post?

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Suryateja Pericherla

Suryateja Pericherla, at present is a Research Scholar (full-time Ph.D.) in the Dept. of Computer Science & Systems Engineering at Andhra University, Visakhapatnam. Previously worked as an Associate Professor in the Dept. of CSE at Vishnu Institute of Technology, India.

He has 11+ years of teaching experience and is an individual researcher whose research interests are Cloud Computing, Internet of Things, Computer Security, Network Security and Blockchain.

He is a member of professional societies like IEEE, ACM, CSI and ISCA. He published several research papers which are indexed by SCIE, WoS, Scopus, Springer and others.

Leave a Reply

Your email address will not be published. Required fields are marked *