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

Palak Patel08 May 2026
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.

Comments

0/1000

No comments yet. Be the first!