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
Output:#include #include 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; }
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.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.