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

# Syntax and example of getche()

Computer Programming · Chapter 4: Input and Output

- Asked in: 2071 Shrawan, 1 marks
- Video: [getche( ) Function in C (Urdu/Hindi)](https://www.youtube.com/watch?v=7qFyIVrhnVQ) — IT Series
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_1/computer_programming/syntax-getche
- Whole chapter: https://www.bctengineer.com/md/semester_1/computer_programming/chapter-4

## Question

Write syntax, example and use of getche().

## Short answer

getche() reads a single character from keyboard, echoes it, and does not wait for Enter. It requires <conio.h> and is used for immediate input like menu choices. Example: char ch = getche();

## Answer

`getche()` reads one character from the keyboard **and echoes it on the screen**, without waiting for the Enter key. It is declared in `<conio.h>` (Turbo C / Windows compilers; not in gcc). The "e" stands for echo.

**Syntax:** `ch = getche();`

**Example (Turbo C):**
```text
char ch;
printf("Enter a letter: ");
ch = getche();          /* character is shown as typed */
printf("\nYou typed %c", ch);
```

**Use:** to read a single-key response (such as Y/N or a menu choice) immediately, with the typed key visible to the user. In standard C, `getchar()` does a similar job but waits for Enter:
```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 does the e in getche() stand for?
   A. Enter
   B. Echo
   C. End
   D. Error
   Answer: B. It echoes the typed character. (Key point: e meaning)

2. getche() differs from getch() because it:
   A. Shows the typed character
   B. Waits for Enter
   C. Reads strings
   D. Is in stdio.h
   Answer: A. Both read without Enter, but getche echoes. (Key point: Behaviour)

3. A suitable use of getche() is:
   A. Y/N or menu response read at a keypress with the key visible
   B. Hiding passwords
   C. Writing files
   D. Printing
   Answer: A. It reads a single key immediately with the key shown. (Key point: Use)
