3元运算符 ? : 的一些用法

#include <stdio.h>
#include <printf.h>

int main()
{
	int a = 5, b = 99, c = 0, d=0, e=7, f=6;
	c = a>0 ?: b;
	d = a<0 ?: b;
	e = e ?: b;
	//f = f? b: ; /*illegal usage, compile error*/
	printf("c=%d\n",c);
	printf("d=%d\n",d);
	printf("e=%d\n",e);
	printf("f=%d\n",f);
	return 0;
}
c=1
d=99
e=7
f=6

 

 

猜你喜欢

转载自blog.csdn.net/qingfengjuechen/article/details/106573970
今日推荐