Javatpoint Logo
Javatpoint Logo

What is getch() in C?

The getch() is a predefined non-standard function that is defined in conio.h header file. It is mostly used by the Dev C/C++, MS- DOS's compilers like Turbo C to hold the screen until the user passes a single value to exit from the console screen. It can also be used to read a single byte character or string from the keyboard and then print. It does not hold any parameters. It has no buffer area to store the input character in a program.

Why we use a getch() function?

We use a getch() function in a C/ C++ program to hold the output screen for some time until the user passes a key from the keyboard to exit the console screen. Using getch() function, we can hide the input character provided by the users in the ATM PIN, password, etc.


Parameters: The getch() function does not accept any parameter from the user.

Return value: It returns the ASCII value of the key pressed by the user as an input.

Write a simple program to display the character entered by the user using the getch() function in C.



Passed value by the User is: P

To print any character on the console, press the corresponding key.

Write a simple program to hold the console screen until the user gives a key to exit.



Enter a key to exit the console screen.

Write a program to use the getch() function to accept the string from the user.



Received 5 character Input: hello

Write a program to use the getch() function to accept the hidden password from the user.



Enter password: **********
You have passed the hidden password: Password@1

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA