Techically, C allows you to "shorten" a variable by assigning it to something that is smaller than itself. The specification doesn't say EXACTLY what happens when you do that (because of technicalities in some machines where slightly weird things happens), but in practice, on nearly all machines that you are likely to use unless you work on museum pieces or some very special hardware, it simply acts as if the "upper" bits of the larger number has been "cut off".
And in this particular case, getc
is specifically designed to return something that fits in a char
, except for the case when it returns EOF
, which often has the value -1
. Although quite often, char
may well support having the value -1
too, but it's not guaranteed to be the case (if char
is an unsigned type - something the C and C++ standards support equally with char
being a signed type that can be -1
).