Home / Questions / What is the difference between getch() and getche()?
Explanatory Question

What is the difference between getch() and getche()?

👁 1,850 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

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


#include<stdio.h>  
#include<conio.h>  
int main()  
{  
      
 char ch;  
 printf("Enter a character ");  
 ch=getch(); // taking an user input without printing the value.  
 printf("\nvalue of ch is %c",ch);  
 printf("\nEnter a character again ");  
 ch=getche(); // taking an user input and then displaying it on the screen.  
  printf("\nvalue of ch is %c",ch);  
 return 0;  
}  

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.