C语言三目运算符?: 1说明 res=expression?a:b expression成立返回结果a,否则返回结果b 2实例 #include <stdio.h> int main(int argc, char const *argv[]) { int a = 10; int b1 = a>2 ? 1:0; int b2 = a<2 ? 1:0; printf("b1=%d,b2=%d\n",b1,b2); return 0; } /** * save as "test.c" * $gcc test.c * $ ./a.out * b1=1,b2=0 */