1.

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

Answer»

Both these C FUNCTIONS read CHARACTERS from the keyboard, the only DIFFERENCE being:

  • GETCH() is a function that reads characters from the keyboard without using any buffers. As a result, no data is presented on the screen.
  • getche() uses a buffer to read characters from the keyboard. As a result, information is displayed on the screen.

Here is an example to demonstrate the difference between the two functions:

#include&LT;stdio.h>#include<conio.h>int main(){ char c; printf("Enter a character here: "); c = getch(); printf("nYou entered the character: %c",c); printf("nEnter another character: "); c = getche(); printf("nYour new entered character is: %c",c); return 0;}

Output:

Enter a character here:You entered the character: cEnter another character: bYour new entered character is: b

getch() immediately returns the character without waiting for the enter key to be pressed and the character is not displayed on the screen. getche() displays the character on the screen without waiting for the enter key to be pressed.



Discussion

No Comment Found