The ternary operator ?: Is an if minimization if that can reduce this:
if(foo) exprIfTrue(); else exprIfFalse();
For this:
(foo) ? exprIfTrue() : exprIfFalse() ;
Personally, I do not use it, because it easily becomes unreadable. The only good use case is displaying the status of a flag in printf :
int my_flag = 1; printf("My flag: %s\n", my_flag ? "TRUE" : "FALSE" );
source share