In C, why is sizeof(char) 1, when 'a' is an int?

后端 未结 5 1256
無奈伤痛
無奈伤痛 2020-11-27 06:50

I tried

printf(\"%d, %d\\n\", sizeof(char), sizeof(\'c\'));

and got 1, 4 as output. If size of a character is one, why does \'c\'

5条回答
  •  时光取名叫无心
    2020-11-27 07:06

    Th C standard says that a character literal like 'a' is of type int, not type char. It therefore has (on your platform) sizeof == 4. See this question for a fuller discussion.

提交回复
热议问题