I am using the ? operator and i want to express the following
(a > b) ? (max = a) : (); // basically i want expression after `:` to be null
If i leave empty brackets after : the compiler complains in-correct syntax. What is the correct syntax for leaving expression after : empty?
if (a > b) max = a;is more concise, if we’re counting characters. Which is a terrible metric.Ideally, your ternary operators should not cause side-effects. Hiding side-effects inside a ternary operator makes code harder to read/debug/maintain etc.
If you want side-effects, don’t get the ternary operator involved.
If you wanted to use the ternary operator for the sake of it, consider
max = (a > b) ? a : max.