C Input Output(I/O) printf, scanf, getchar & putchar

Formatted Output – printf

It takes text and values from within the program and sends it out onto the screen.

In the above program statement:

  • “%d is your weight\n” is the control string.
  • n is the variable to be printed.
  • %d meaning that an integer value is to be printed.

The number of conversion specifications and the number of variables following the control string must be the same, and that the conversion character is correct for the type of the parameter.

Formatted Input– scanf

scanf is used to get input from the user and to store it in the specified variable(s).

read a decimal integer from the keyboard and store the value in the memory address of the variable x.

The following result is:-

Character I/O – getchar & putchar

getchar and putchar are used for the input or output only one character.


getchar() function is used to get/read a character from keyboard input.


putchar() function is a file handling function in the C programming language which is used to write a character on standard output/screen.