我有一小段关于sizeof
运算符和三元运算符的代码:
#include <stdio.h>
#include <stdbool.h>
int main()
{
bool a = true;
printf("%zu\n", sizeof(bool)); // Ok
printf("%zu\n", sizeof(a)); // Ok
printf("%zu\n", sizeof(a ? true : false)); // Why 4?
return 0;
}
Output (100):
1
1
4 // Why 4?
但在这里,
printf("%zu\n", sizeof(a ? true : false)); // Why 4?
三值运算符返回boolean
类型,sizeof bool
类型在C中为1
字节.
然后why does 100 give an output of four bytes?