To add the good answers provided by Jack and Hot Fix, determining what to use is partly dependent on need and partly on style. For example,?: As a rule, it reduces redundancy, which can lead to simpler and shorter codes that are easier to read and simplify for maintenance - there is no risk of updating one half of if..else and forgetting the other. eg.
int result = SomeFunction(arg1, arg2, arg3, (someBool ? arg4a : arg4b));
against
int result = -1; if (someBool) { result = SomeFunction(arg1, arg2, arg3, arg4a); } else { result = SomeFunction(arg1, arg2, arg3, arg4b); }
This is a short example for brevity, but you can imagine that with real argument names and complex complexity it would be easy to return after a few months from now and change the second call of SomeFunction, without understanding the other, there is, not to mention the need, you can also change .
source share