What is getch() in C?

getch is a nonstandard predefined function in C. It is mostly used in MS-DOS compilers. Its function is to hold the screen until the user passes a single value to exit from the console screen.

It is defined in conio.h header file. It has no buffer to the area to store the input character in a program. It is mainly used to hide the input characters provided by the user in ATM PIN, password,..


Prototype

int getch(void);

Return value

It returns the ASCII value of the key pressed by the user. The entered key does not show up on console.


Example program for getch()

// C program to illustrate getch()
#include<stdio.h>
#include<conio.h>
int main()
{
  printf("Press any key to exit \n");
  getch();
  return 0;
}

Output

getch in

People also ask for

What is the use of getch() in C?

Its function is to hold the screen until the user passes a single value to exit from the console screen.

why we use getch in c?

Its purpose is to keep the screen on the screen until the user inputs.

What is the header file for getch?

getch() is defined in conio.h header file.