表达式1 ? 表达式2 :表达式3
表达式1为真,则跳到表达式2,否则跳到表达式3
最简单的应用,比较两个数的大小
#include <stdio.h>
int main()
{
int a = 1,b = 2,c = 3;
int d = (a > b ? a : b);
printf("%d\n",d);
return 0;
}
#include <stdio.h>
int main()
{
int a = 1,b = 2,c = 3;
int d = (a > b ? 3 : -5);
printf("%d\n",d);
return 0;
}