What is the difference between getch() and getche() in C Language?

The getch() function reads a single character from the keyboard. It doesn’t use any buffer, so entered data will not be displayed on the output screen.

The getche() function reads a single character from the keyword, but data is displayed on the output screen. Press Alt+f5 to see the entered character.

Let’s see a simple example

  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main()
  4. {
  5.  char ch;
  6.  printf(“Enter a character “);
  7.  ch=getch(); // taking an user input without printing the value.
  8.  printf(“\nvalue of ch is %c”,ch);
  9.  printf(“\nEnter a character again “);
  10.  ch=getche(); // taking an user input and then displaying it on the screen.
  11.   printf(“\nvalue of ch is %c”,ch);
  12.  return 0;
  13. }

Output:

Enter a character
value of ch is a
Enter a character again a
value of ch is a

In the above example, the value entered through a getch() function is not displayed on the screen while the value entered through a getche() function is displayed on the screen.