【发布时间】:2018-03-30 03:31:24
【问题描述】:
我写了关于sizeof 运算符的代码。如果我写类似:
#include <stdio.h>
int main() {
char a[20];
printf("%zu\n", sizeof(a));
return 0;
}
输出:
20 // Ok, it's fine
但是,如果我像这样使用 逗号 运算符:
#include <stdio.h>
int main() {
char a[20];
char b;
printf("%zu\n", sizeof(b, a));
return 0;
}
输出:
8 // Why the output 8?
所以,我有一个问题:
- 为什么编译器会在第二个示例中给出输出
8? -
comma运算符转换为sizeof()运算符的行为是什么?
【问题讨论】: