The ternary operator ?:
is a minimize if
statement which can reduce this:
if(foo)
exprIfTrue();
else
exprIfFalse();
To this:
(foo) ? exprIfTrue() : exprIfFalse() ;
Personally, I avoid using it because it easily becomes unreadable. The only good example of use is to display the status of a flag in a printf
:
int my_flag = 1;
printf("My flag: %s\n", my_flag ? "TRUE" : "FALSE" );