<分区>
Possible Duplicate:
Why are C character literals ints instead of chars?
int main(void)
{
printf("%d %d\n", sizeof('c'), sizeof(char));
return 0;
}
为什么 sizeof('c')
返回 4 而不是 1?
标签 c
<分区>
Possible Duplicate:
Why are C character literals ints instead of chars?
int main(void)
{
printf("%d %d\n", sizeof('c'), sizeof(char));
return 0;
}
为什么 sizeof('c')
返回 4 而不是 1?
最佳答案
因为在 C 中,字符常量的类型是 int
,而不是 char
。所以 sizeof('c') == sizeof(int)
。引用这个C FAQ
Perhaps surprisingly, character constants in C are of type int, so sizeof('a') is sizeof(int) (though this is another area where C++ differs).
关于c - 为什么 sizeof ('c' ) 返回 4 而不是 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702511/