What is the difference between getc(), getchar(), getch() and getche()?

Difference Between getc(), getchar(), getch() and getche()
These functions are used in C programming to take character input from the user.
Although they appear similar, their behavior and usage are different.
Comparison Table
| Function | Header File | Echoes Character? | Needs Enter Key? | Main Use |
|---|---|---|---|---|
| getc() | stdio.h | Yes | Yes | Reads character from file or stdin |
| getchar() | stdio.h | Yes | Yes | Reads single character from keyboard |
| getch() | conio.h | No | No | Takes hidden character input |
| getche() | conio.h | Yes | No | Takes visible character input |
1. getc()
getc() reads a single character from a file or standard input.
Syntax:
ch = getc(file_pointer);
Example:
ch = getc(stdin);
It requires pressing the Enter key.
2. getchar()
getchar() reads one character from the keyboard.
Syntax:
ch = getchar();
It also requires pressing Enter after typing the character.
3. getch()
getch() reads a character directly from the keyboard without displaying it on the screen.
Syntax:
ch = getch();
It does not require the Enter key.
4. getche()
getche() reads a character and displays it immediately on the screen.
Syntax:
ch = getche();
It also works without pressing Enter.
Main Difference
- getc() and getchar() require Enter key.
- getch() and getche() do not require Enter key.
- getch() hides the typed character.
- getche() shows the typed character.
Conclusion
All four functions are used for character input, but they behave differently based on visibility and keyboard handling.
Understanding these differences is important for C programming input operations.

Written by
Palak PatelEducation writer Palak Patel covers the latest education news, board exam updates, results, and career opportunities.
Comments
No comments yet. Be the first!
