Quote Originally Posted by Valour549
So it's safe to conclude that outside of EOF conditions, declaring the variable as int or char makes no difference at all, but since int is the more inclusive one, we should always declare the variable as an int?
I think it would be enlightening to look at the official description of getchar:
Quote Originally Posted by C11 7.21.7.6
The getchar function is equivalent to getc with the argument stdin.
Quote Originally Posted by C11 7.21.7.5
The getc function is equivalent to fgetc (...)
Quote Originally Posted by C11 7.21.7.1
Code:
#include <stdio.h>
int fgetc(FILE *stream);
Description
If the end-of-file indicator for the input stream pointed to by stream is not set and a next character is present, the fgetc function obtains that character as an unsigned char converted to an int and advances the associated file position indicator for the stream (if defined).
Returns
If the end-of-file indicator for the stream is set, or if the stream is at end-of-file, the end-of-file indicator for the stream is set and the fgetc function returns EOF. Otherwise, the fgetc function returns the next character from the input stream pointed to by stream. If a read error occurs, the error indicator for the stream is set and the fgetc function returns EOF.
The key here is that "the fgetc (and hence getchar) function obtains that character as an unsigned char converted to an int". This means that the value of the character is always non-negative, since an unsigned char is always non-negative. At the same time, you know from jimblumberg's post #14 that the standard says that the value of EOF is always negative. Therefore, this means that a non-EOF value returned by getchar will never ever conflict with getchar returning EOF, but for that to be the case you should store the return value of getchar in an int.

So in a sense what john.c says in post #10 isn't quite true: getchar doesn't necessarily return an integer larger than a char; rather, it is designed such that the range of what getchar would normally return is disjoint from the range of what getchar would return on an error or end-of-file. But his overall point remains: if you store the return value of getchar in a char instead of an int, then you could find yourself misinterpreting EOF for a normal character read.