【发布时间】:2012-01-20 14:54:45
【问题描述】:
我今天只是在我的 c 课上玩三元运算符。并发现了这种奇怪的行为。
#include <stdio.h>
#include <stdbool.h>
main()
{
int x='0' ? 1 : 2;
printf("%i",x);
}
returns 1 符合预期。但是
#include <stdio.h>
#include <stdbool.h>
main()
{
int x='0'==true ? 1 : 2;
printf("%i",x);
}
returns 2 而我希望它是return 1。
【问题讨论】:
标签: c ternary-operator