<分区>
char c = 'A';
printf("%d\n",sizeof(c));// output = 1
printf("%d\n",sizeof('A')); // output = 4
为什么 sizeof
运算符对同一个字符给出不同的输出?请帮忙
<分区>
char c = 'A';
printf("%d\n",sizeof(c));// output = 1
printf("%d\n",sizeof('A')); // output = 4
为什么 sizeof
运算符对同一个字符给出不同的输出?请帮忙
最佳答案
c
是char
类型的变量;它的大小是 1 个字节。
'A'
是一个 int
字面量 - 不要问我标准为什么这么说。它的大小在您的平台上是 4 个字节(与 sizeof(1)
相同)。
关于c - 了解 C 中的 sizeof 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34428263/