The C11 standard says that character constants (e.g., 'x'
) are of type int
, not char
. This surprised and confused me (especially as a relative beginner). I came across this answer Why are C character literals ints instead of chars?, which somewhat cleared things up, but still left me wondering why it seems to be routine practice (at least in all the books and tutorials I've come across) to assign character constants to variables that are declared to be of type char
. For example, why do we do
char initial = 's';
and not
int initial = 's';
And then, what happens when a constant of type int
is assigned to a variable of type char
? Is it switched into type char
?