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

后端 未结 5 1272
無奈伤痛
無奈伤痛 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:14

    According to the ANSI C standards, a char gets promoted to an int in the context where integers are used, you used a integer format specifier in the printf hence the different values. A char is usually 1 byte but that is implementation defined based on the runtime and compiler.

提交回复
热议问题