---
title: "Syntax and example of getch()"
subject: "Computer Programming"
chapter: 4
key: "semester_1/computer_programming:syntax-getch"
source: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-getch
site: BCT Engineering
---

# Syntax and example of getch()

Computer Programming · Chapter 4: Input and Output

- Asked in: 2071 Shrawan, 1 marks; 2071 Chaitra, 1 marks (asked 2 times)
- Video: [getch Function || getche Function in C language](https://www.youtube.com/watch?v=_aJ7abvA0OI) — Computer Study Studio
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-getch
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-4

## Question

Write syntax, example and use of getch().

## Short answer

getch() (from <conio.h>) reads a single keypress without echoing and without waiting for Enter. Syntax: ch = getch();. Used for password input or to hold the screen; for standard C, getchar() provides similar functionality but requires Enter and echoes.

## Answer

`getch()` reads one character from the keyboard **without displaying it** (no echo) and without waiting for the Enter key. It is declared in `<conio.h>` (a non-standard header of Turbo C and Windows compilers).

**Syntax:** `ch = getch();` or simply `getch();`

**Example (Turbo C):**
```text
char ch;
printf("Enter password character: ");
ch = getch();       /* key is read but not shown */
printf("\nYou pressed %c", ch);
```

**Uses:**
- reading passwords and secret input, since typed characters are not echoed;
- holding the output screen until a key is pressed (`getch();` at the end of `main`);
- menu choices that should react on a single keypress.

`conio.h` is not available in gcc. The portable standard function `getchar()` does the same job but needs the Enter key and echoes the character:
```c
#include <stdio.h>
int main(void)
{
    char ch;
    printf("Press a key: ");
    ch = getchar();     /* portable counterpart of getch()/getche() */
    printf("You pressed: %c\n", ch);
    return 0;
}
```
Output for the key `k`:
```text
Press a key: You pressed: k
```

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is the key behaviour of getch()?
   A. Reads a char and shows it, waiting for Enter
   B. Reads a char without showing it and without Enter
   C. Reads a whole line
   D. Prints a char
   Answer: B. getch does not echo and does not wait for Enter. (Key point: Echo)

2. Which header declares getch()?
   A. <stdio.h>
   B. <conio.h>
   C. <string.h>
   D. <math.h>
   Answer: B. It is in non-standard <conio.h>, not available in gcc. (Key point: Header)

3. A suitable use of getch() is:
   A. Reading a password
   B. Printing floats
   C. Opening files
   D. Sorting
   Answer: A. Typed characters are not echoed, which suits passwords. (Key point: Use)
