Join us Now |  Forgot Password? | Forgot UserName?


Learn step by step

C Input/Output

ANSI standard has defined many library functions for input and output in C language. Function scanf() and printf() are the most commonly used to take input and display output respectively. We consider an example:

#include <stdio.h> //To run printf() function.
int main()
printf("Tuton - Redefining online Education"); //displays the content inside quotation
return 0;

Explanation of How this program works
  • Every program starts from main() function.
  • printf() is a C library function to display output which only works if #include is included at the beginning.
  • Here, stdio.h is a header file (standard input output header file) and #include is command to paste the code from the header file when necessary. When compiler encounters printf() function and if it doesn't find stdio.h header file, compiler will shows error.
  • Code return 0; indicates the end of the program. You can ignore return 0; statement but, it is good practice to use return 0 in program.
I/O of integers in C:

int main()
int p=12;
return 0;

I/O of floats in C:

int main()
float q;
printf("Enter value: ");
printf("Value=%f",q); //%f is used for floats instead of %d
return 0;

Conversion format string "%f" is used for floats to take input and to display floating value of a variable.

I/O of characters and ASCII code:

#include <stdio.h>
int main(){
char var1;
printf("Enter character: ");
printf("You entered %c.",var1);
return 0;


Enter character: g
You entered g.

Conversion format string "%c" is used in case of characters.

For more details how ASCII character code work click here.

Related Videos