"Do nothing" in the else-part of the ternary operator?

Viewed 10793

What's the standard line to add to the ternary operator in order to do nothing if the condition is not met?

Example:

int a = 0;
a > 10 ? a = 5 : /*do nothing*/;

Using a seems to do the trick, but I am wondering if there is a more generally accepted way.

5 Answers

You can also use a logical expression (though maybe confusing) in case you don't want to use an if statement.

a > 10 && a = 5

Just for a sake of variety, but not recommending as it is very ambiguous.

void do_smth()
{}

bool a = true; // not necessarily 

a && (do_smth(), 0);
Related