getch() Library Functions with Examples

getch() is character input functions. It is unformatted input function meaning it does not allow user to read input in their format. It reads a character from the keyboard but does not echo the pressed character and returns character pressed. It is defined in header file conio.h.

getch() Syntax

character_variable = getch();

getch() Examples

Example #1 : Reading Character Using getch() & Displaying


void main()
  char ch;
  printf(“Press any character: ”);
  ch = getch();
  printf(“\nPressed character is: %c”, ch);

Output of above example :

Press any character: 
Pressed character is: e

Note: while using getch() pressed 
character is not echoed. Here pressed 
character is e and it is displayed 
by printf().