In general, yes, they are the same.
But they are not in a few insignificant ways. The getchar function getchar printed to return int , not char . This is done so that getchar can both all possible char values ββand error codes.
So, if the following compilation is done on most compilers, you essentially truncate the error message
char c = getchar();
The scanf function, however, allows you to directly use the char type and separates the error code from the return value.
Jaredpar
source share