getch() function in C with Examples Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report getch() is a nonstandard function and is present in conio.h header file which is mostly used by MS-DOS compilers like Turbo C. It is not part of the C standard library or ISO C, nor is it defined by POSIX.Like these functions, getch() also reads a single character from the keyboard. But it does not use any buffer, so the entered character is immediately returned without waiting for the enter key.Syntax: int getch(void);Parameters: This method does not accept any parameters.Return value: This method returns the ASCII value of the key pressed.Example: C // Example for getch() in C #include <stdio.h> // Library where getch() is stored #include <conio.h> int main() { printf("%c", getch()); return 0; } Input: g (Without enter key)Output: Program terminates immediately. But when you use DOS shell in Turbo C, it shows a single g, i.e., 'g'Important Points regarding getch() method: getch() method pauses the Output Console until a key is pressed.It does not use any buffer to store the input character.The entered character is immediately returned without waiting for the enter key.The entered character does not show up on the console.The getch() method can be used to accept hidden inputs like password, ATM pin numbers, etc.Example: To accept hidden passwords using getch()Note: Below code won't run on Online compilers, but on MS-DOS compilers like Turbo IDE. C // C code to illustrate working of // getch() to accept hidden inputs #include <conio.h> #include <dos.h> // delay() #include <stdio.h> #include <string.h> void main() { // Taking the password of 8 characters char pwd[9]; int i; // To clear the screen clrscr(); printf("Enter Password: "); for (i = 0; i < 8; i++) { // Get the hidden input // using getch() method pwd[i] = getch(); // Print * to show that // a character is entered printf("*"); } pwd[i] = '\0'; printf("\n"); // Now the hidden input is stored in pwd[] // So any operation can be done on it // Here we are just printing printf("Entered password: "); for (i = 0; pwd[i] != '\0'; i++) printf("%c", pwd[i]); // Now the console will wait // for a key to be pressed getch(); } Output: Abcd1234Output: Enter Password: ********Entered password: Abcd1234 Comment More infoAdvertise with us Next Article Beep() function in C with Examples A AnshulVaidya Follow Improve Article Tags : C Programs Programming Language C Language Similar Reads Beep() function in C with Examples The Beep function in C is used to make a Beep sound. It generates a tone on the speaker. The function is synchronous, i.e. it waits and doesn't return to its caller function until the sound is finished. It can be very useful during the Debugging process for finding errors.Header File:Â Â #include 2 min read Beep() function in C with Examples The Beep function in C is used to make a Beep sound. It generates a tone on the speaker. The function is synchronous, i.e. it waits and doesn't return to its caller function until the sound is finished. It can be very useful during the Debugging process for finding errors.Header File:Â Â #include 2 min read Beep() function in C with Examples The Beep function in C is used to make a Beep sound. It generates a tone on the speaker. The function is synchronous, i.e. it waits and doesn't return to its caller function until the sound is finished. It can be very useful during the Debugging process for finding errors.Header File:Â Â #include 2 min read time.h header file in C with Examples The time.h header file contains definitions of functions to get and manipulate date and time information. It also includes functions, types, and macros, which are used by programs to measure time, manipulate dates, and format time information. It describes three time-related data types. clock_t: clo 6 min read time.h header file in C with Examples The time.h header file contains definitions of functions to get and manipulate date and time information. It also includes functions, types, and macros, which are used by programs to measure time, manipulate dates, and format time information. It describes three time-related data types. clock_t: clo 6 min read time.h header file in C with Examples The time.h header file contains definitions of functions to get and manipulate date and time information. It also includes functions, types, and macros, which are used by programs to measure time, manipulate dates, and format time information. It describes three time-related data types. clock_t: clo 6 min read Like