In C, we could use ternary like
( a == 4) ? a = b: a = 5;
Someone told me better not using it, how do you think?
The conditional operators is useful for forming expressions. Use it when you need an expression which depends, well, on a condition. Don't use it to make statements. For example, your code could be a statement:
if (a == 4) { a = b; }
else { a = 5; }
Or you could write it with a conditional expression, but idiomatically like this:
a = (a == 4 ? b : 5);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments