• admin@embedclogic.com

Input/Output in C

When we talking about the Input, it means value taken in the program from outside world.So in C language when we say input taken from outside means value entered on the keyboard will transfer to our program.

The same concept for output, when we say output it means our program is going to display some result on some screen.

In C language programming everything is a file whether it is some text file or peripheral like screen, keyboard etc.  In C language, Pointers are defined in the standard library for console device.

See the below table for the pointers to Console input, output and error device.

Standard FileFile PointerConsole device  
Standard inputstdinKeyboard
Standard outputstdoutScreen
Standard errorstderrScreen

Console Input and Output Function


int getchar(void); 

This function picks next available character from stdin pointer(keyboard) and return an integer.


int putchar(int);

 This functiontakes an integer as an input which is to be print and give that value to stdout pointer to print at the screen.

Note: You can use these function in the loop for multi-character input.


char* gets(char *string); 

This function takes input into buffer string from console pointer stdin until a newline or EOF not met.


int puts(char *string); 

This function takes a string(array of character terminates with NULL) as an input which is to be print and pass to stdout pointer to print at the screen.It returns the number of characters printed o the screen.

scanf() :

int scanf(const char *format,…);

This function reads input from stdin buffer according to format specifier described in its first argument.it returns “total count of input values”.

Input data TypeData Format Specifier   
Decimal or Real values%f,%lf,%Lf



int printf(const char *format, …);

The printf() writes output to standard output stream stdout in the required format specifier.

Sample Program for Input-output function demonstration

Write a program for two integer number Addition and integers values shall input from the keyboard: