In C, why is sizeof(char) 1, when 'a' is an int?
It is the normal behavior of the sizeof
operator (See Wikipedia):
- For a datatype,
sizeof
returns the size of the datatype. Forchar
, you get 1. - For an expression,
sizeof
returns the size of the type of the variable or expression. As a character literal is typed asint
, you get 4.