Difference between getchar, getch function provided by c in table.



 Both getchar() and getch() are functions in C programming language that are used for reading input characters from the keyboard. However, there are some differences between these two functions, which are summarized in the table below:

Functiongetchar()getch()
Header#include <stdio.h>#include <conio.h>
Return typeintint
InputReads the next character from stdinReads the next character
(standard input)from the keyboard
UsageUsed for standard I/O operationsUsed for console I/O operations
BufferingUses buffered input, waits for Enter keyDoes not use buffered input,
to submit inputdoes not wait for Enter key
CompatibilityWorks on all platforms including Windows,Works only on Windows platform
Linux, and macOS

In summary, getchar() reads the next character from standard input (usually the keyboard) and buffers the input until Enter key is pressed, while getch() reads the next character from the keyboard without buffering and does not wait for the Enter key. getchar() is a standard I/O function and is portable across different platforms, while getch() is a console I/O function and is specific to the Windows platform.

Post a Comment

Previous Post Next Post