putchar() Library Function with Examples

The putchar() function is used for printing character to a screen at current cursor location. It is unformatted character output functions. It is defined in header file stdio.h.

putchar() Syntax


putchar(character);
	or
putchar(character_variable);

putchar() Examples

Example #1 : Displaying Character Using putchar()


#include<stdio.h>
#include<conio.h>

void main()
{
  char ch;
  clrscr(); /* Clear the screen */
  printf(“Press any character: ”);
  ch = getche();
  printf(“\nPressed character is:”);
  putchar(ch);
  getch(); /* Holding output */
}

Output of the above program :

Press any character: f
Pressed character is: f


Note: while using getche() pressed character 
is also echoed. Here pressed character is f 
and it is displayed by putchar() later.