For historical reasons (mostly), character constants are of type int
in C.
But even if they weren't, an initialization like
int num = 'a';
or an assignment like
num = 'a';
would still be perfectly legal. A value of any numeric type may be assigned to a variable of any (other) numeric type, and the value will be implicitly converted (which may involve a change of representation and/or a risk of overflow).
And char
, along with its relatives unsigned char
and signed char
, are numeric types, specifically integer types.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…