小编Nig*_*n23的帖子

为什么在printf中指定为整数的char被正确打印

为什么以下代码有效?

char c = 'A';
printf("%d - size: %d", c, sizeof(c));
Run Code Online (Sandbox Code Playgroud)

打印出来:

65 - size: 1
Run Code Online (Sandbox Code Playgroud)

为什么输出不是垃圾,因为int通常是4个字节长,我们可以清楚地看到char是1个字节长.编译器是否进行隐式对话?

c printf types stdio type-conversion

3
推荐指数
2
解决办法
162
查看次数

标签 统计

c ×1

printf ×1

stdio ×1

type-conversion ×1

types ×1