The only predefined
operator in
c and
c++ (I'm not sure about other
languages) which takes three
operands.
foo == bar ? foo = baz : bar = baz;
The above
code first executes
foo == bar. If it
evaluates to true, the first statement,
foo = baz is executed; if it evaluates to
false,
bar = baz is executed.
In my humble opinion, these make your code look a whole lot more 'leet than if and else statements.
Warning: Strangely enough, return () statements don't seem to work with this operator, even though I can't find any documentation that tells me why. Anybody who tells me why (or shows me where to find out) gets a cookie.
Oh, and apparently my last paragraph wasn't clear. Here's what I mean:
foo == bar ? return (foo) : return (baz);
Doesn't work. Of course,
return (foo == bar ? foo : baz);
Does work....But I prefer the non-working version. Oh well.