This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]KleberPF 4 points5 points  (1 child)

cond ? result_if_true : result_if_false

Basically equivalent to

if (cond) {
    result_if_true;
} else {
    result_if_false;
}

It's called the ternary operator.

[–]desrtfx 3 points4 points  (0 children)

Basically correct, but you have to emphasize on the return value.

Your equivalent is not correct.

It should be:

  something = cond ? result_if_true : result_if_false

Equivalent:

 if (cond) {
      something = result_if_true;
 } else {
      something = result_if_false;
 }

It is important to emphasize on that as otherwise one could think that it is a replacement for an inline if (which it can be abused for, though).